淘汰赛:绑定到表时无法更新淘汰赛中的可观察数组

时间:2021-07-03 16:18:00

标签: knockout.js knockout-3.0

我有两张桌子。在一个表(父表)中,我可以选择添加和删除该列中的行是下拉列。根据选择,我需要用数据加载另一个表(子表)。我能够在父表上进行操作。但是在子表上,我无法将数据推送到表中,尽管我可以看到我能够将数据传递到子表。但表中没有填充数据。

这是我的儿童桌

<div id="childDiv">
        <table data-bind='visible: chldItem().length > 0'>
            <thead>
                <tr>
                    <th>Header1</th>
                    <th>Header2</th>
                    <th />
                </tr>
            </thead>
            <tbody data-bind='foreach: chldItem'>
                <tr>
                    <td><input class='required' data-bind='value: text, uniqueName: true' /></td>
                    <td><input class='required number' data-bind='value: defaultValue, uniqueName: true' /></td>
                </tr>
            </tbody>
        </table>
</div>

这是子表的视图模型。

var ChildModel = function(chldItem) {
    var self = this;
    self.chldItem = ko.observableArray([]);
    if(chldItem.length > 0){
        self.chldItem.push(chldItem);
    }
};

ko.applyBindings(new ChildModel([]), document.getElementById('childDiv'));

// 从父下拉列表更改

self.childConfig.push(1, new ChildModel(clearVM);

这是当前版本代码的小提琴。 http://jsfiddle.net/oneplusbot/xa90cymz/5/

当我选择第一个下拉列表时,我期待它会有 4 行,第二个它会显示 2 行

0 个答案:

没有答案