我有这个视图模型结构:
function PluginViewModel(name, code) {
var self = this;
self.name = ko.observable(name);
self.code = ko.observable(code);
}
function item() {
var self = this;
self.id = ko.observable();
self.listIndex = ko.observable();
self.value = ko.observable();
self.label = ko.observable();
self.tabPos = ko.observable();
self.plugins = ko.observableArray();
};
function TableViewModel() {
var self = this;
self.columns = ko.observableArray();
self.filteredColumns = ko.observableArray();
// To bind View Fields List
self.selectedColumn = ko.observable();
self.selectColumn = function (p) {
self.selectedColumn(p);
}
// To bind Table Columns List
self.tmpColSelected = ko.observable();
self.tmpColSelect = function (p) {
self.tmpColSelected(p);
}
// Plugin selected
self.selectedPlugin = ko.observable();
self.selectPlugin = function (p) {
self.selectedPlugin(p);
}
// New Plugin
self.newPlugin = ko.observable();
self.addPlugin = function () {
self.selectedColumn().plugins.push(self.newPlugin());
$('#dialogAddPlugin').wijdialog('close');
}
}
function SchemaViewModel() {
var self = this;
self.name = ko.observable();
self.tables = ko.observableArray();
self.selectedTable = ko.observable();
self.selectTable = function (p) {
self.selectedTable(p);
}
}
然后这是绑定代码:
schema = new SchemaViewModel();
ko.applyBindings(schema);
有一个主从场景,其中一个无序的 html 列表与 tableViewModel 的 selectedColumn 字段绑定。
选择列表项后,在详细信息视图中,我可以使用显示 Wijmo 对话框的添加按钮添加插件。这是对话框的代码:
<div id="dialogAddPlugin" title="Plugin editor" data-bind="with: newPlugin">
<textarea data-bind="value: code, valueUpdate: 'input'"></textarea>
<div>
Name: <input data-bind="value: name, valueUpdate: 'input'" />
<button id="btnSaveNewPlugin" data-bind="click: $parent.addPlugin">Save</button>
</div>
</div>
问题是即使视图模型似乎设置正确,也永远不会调用 addPlugin 方法。
怎么了?
谢谢