挖空 JS 样式绑定导致错误
Knockout JS style binding causing error
我需要使用 KNOCKOUT js style
属性将background-image
data-bind
到div
。我是数据绑定产品图像。Product.image 是图像文件名的字符串。但是,我需要在文件名之前添加文件的路径。
法典:
<div data-bind="style: { background-image: 'url(../../the_vegan_repository/product_images/'+ product.image + ')' }"
但它会导致以下控制台错误:
未捕获的语法错误:无法分析绑定。 绑定值: 样式: { 背景图像: 'url(../../the_vegan_repository/product_images/'+ product.image } 消息:意外令牌 -
为什么会导致该错误?
这是我的所有代码:
<script type="text/html" id="product-template">
<div class="col-sm-6 col-lg-2 clickable" style="margin-top:20px; padding: 25px;">
<div style="border-radius: 15px; border: 5px solid #fc4747;height: 270px;overflow: hidden;">
<div data-bind="style: { background-image: 'url(../../the_vegan_repository/product_images/'+ product.image + ')' }"
style= "height: 180px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
color: white;
background: center no-repeat;
background-image: url(../../the_vegan_repository/product_images/alpro_custard.jpg);
background-size:cover;
vertical-align:bottom;">
</div>
<div style="height: 90px; padding: 10px; background: #fc4747;">
<h6 class="medium-text" data-bind="text: product.name" style="text-transform: uppercase; color: white; margin-top:0; margin-bottom:5px;"></h6>
<h6 class="medium-text" data-bind="text: shop.name" style="text-transform: uppercase; color: white; margin-bottom:5px;display: inline;"></h6>
<h6 class="medium-text" data-bind="text: shop.suburb" style="text-transform: uppercase; color: white; margin-bottom:5px;display: inline;"></h6>
</div>
</div>
</div>
</script>
这是因为您需要使用骆驼大小写作为backgroundColor
background-color
。参考: http://knockoutjs.com/documentation/style-binding.html
相关文章:
- 绑定函数时在IE7中未实现Javascript错误
- jQuery结合了2个绑定函数(类型错误:a是未定义的)
- 异步面板绑定错误
- javascript onchange取消绑定错误|未定义
- Knockout绑定错误
- IE8中的Ember.js(1.0pre)属性绑定错误
- 反应更改绑定此错误
- 三.js - 没有纹理绑定到单元 0 错误
- 挖空 JS 样式绑定导致错误
- 将服务中的函数绑定到$scope(错误:无法设置undefined的属性'onChange')
- 未捕获的类型错误:对象#<对象>没有方法'绑定'-脊梁骨
- Knockout,无法解析空可观察数组中的绑定错误
- 检测Kendo UI值绑定错误
- 剑道 UI 网格绑定错误
- 通过 for 循环绑定会产生错误的结果
- DOM 绑定错误:未定义侦听器方法
- 挖空 无法解析绑定.引用错误
- 挖空视图模型绑定未定义错误
- 尝试运行节点 http 服务器时出现绑定错误
- 错误绑定引导日期时间选取器到模型角度