我有以下ExtJS模型:
Ext.define('TestsModel', {
name: null,
tests: null,
constructor: function (name) {
this.name = ko.observable(name);
this.tests = ko.observableArray([
{testName: 'FsTest'},
{testName: 'rmDirTest1'},
{testName: 'rmDirTest2'},
{testName: 'mdirTest1'}
]);
}
});
var test = Ext.create('TestsModel');
ko.applyBindings(test);
我想将此模型与下一个模板绑定:
<div>
<p data-bind="text: name"></p>
<table>
<tbody data-bind="text: tests">
<tr>
<td data-bind="text: testName"></td>
</tr>
</tbody>
</table>
</div>
但它不起作用。我收到了错误:
Uncaught TypeError: Cannot read property 'nodeType' of null
如何正确使用Knockout和ExtJS?
答案 0 :(得分:1)
这几乎是正确的。只需使用foreach绑定而不是文本绑定:
<div>
<p data-bind="text: name"></p>
<table>
<tbody data-bind="foreach: tests">
<tr>
<td data-bind="text: testName"></td>
</tr>
</tbody>
</table>
</div>
另外,要查看测试套件的名称,请为构造函数提供name参数
var test = Ext.create('TestsModel', 'My test suite');