【发布时间】:2018-05-07 16:53:31
【问题描述】:
我正在尝试在数据绑定中调用一个函数,但似乎没有任何效果。
这是我的场景:
function ViewModel() {
this.Products = ko.observableArray([]);
this.FormatUrl = function (url) {
...
return ...
}
}
用法:
<tbody data-bind="foreach: Products">
...
<td><div data-bind="attr:{style: images.length > 0 ? 'background-image:url($root.FormatUrl(images[0]));' : ''}" /></td>
...
</tbody>
我还尝试了引用 '$root.Format..' 并得到了 SyntaxError: Unable to parse bindings. Message: Unexpected identifier
调用我的函数的正确方法是什么?
【问题讨论】:
标签: knockout.js