简体   繁体   English

如何绑定ExtJS模型和敲除模板?

[英]How to bind ExtJS model and knockout template?

I have the following ExtJS model: 我有以下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);

I want to bind this model with the next template: 我想将此模型与下一个模板绑定:

<div>
    <p data-bind="text: name"></p>
    <table>
        <tbody data-bind="text: tests">
            <tr>
                <td data-bind="text: testName"></td> 
            </tr>
        </tbody>
    </table>
</div>

but it doesn't work. 但这不起作用。 I got error: 我收到错误消息:

Uncaught TypeError: Cannot read property 'nodeType' of null 

How to should I use Knockout and ExtJS correctly? 如何正确使用Knockout和ExtJS?

It's almost correct. 几乎是正确的。 Just use foreach binding instead of text binding: 只需使用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>

Also to see the name of test suite provide name parameter to the constructor 还可以查看测试套件的名称,向构造函数提供name参数

var test = Ext.create('TestsModel', 'My test suite');

Look at this working sample http://jsfiddle.net/tabalinas/68M8t/ 看看这个工作示例http://jsfiddle.net/tabalinas/68M8t/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM