我正在尝试在 Knockout (3.3.0) 中创建一个简单的组件:
ko.components.register('test', {
viewModel: function() {
this.test = 'hello'
},
template:
`<span data-bind='if: 1, text: test'></span>`
});
ko.applyBindings();
见小提琴。
<test></test>
现在,当我在其他地方实例化 a 时,出现错误:
Multiple bindings (if and text) are trying to control descendant bindings of the same element. You cannot use these bindings together on the same element.
这真的不可能吗?如果您问我,这就像要合并的最基本功能。我知道我可以使用<!-- ko text -->
,但是如何设置其他属性,比如src
同时使用if
呢?