我看到this example下拉变更事件并尝试了但无法让它工作..会感激一些帮助...
我的HTML:
<div data-bind="with: g">
<div><input type="text" class="form-control" data-bind="value: gname" /></div>
<div>
<table>
<tbody>
<tr data-bind="with:gdetails">
<td>
<select data-bind="options: eventschemas, optionsText: 'schema', value:eventschemacondition().schema, event: {change: setschema}"></select>
</td>
</tr>
</tbody>
</table>
<pre data-bind="text: ko.toJSON($data, null, 2)"></pre>
</div>
</div>
</div>
我的javascript:
var eventschemas = [{ "schema": "Test" }, { "schema": "Another Test" }];
var AppScope = function () {
function EventSchemaCondition(data) {
this.schema = ko.observable(data.schema);
this.setschema = function () {
console.log("event fired");
};
}
function Gdetails(data) {
this.eventschemacondition = ko.observable(data.eventschemacondition);
}
function G(data) {
this.gname = ko.observable(data.gname);
this.gdetails = ko.observable(data.gdetails);
}
function GsViewModel() {
var self = this;
self.g = ko.observable(
new G({
gname: "",
gdetails: new Gdetails({ eventschemacondition: new EventSchemaCondition({ schema: "" }) })
}));
}
ko.applyBindings(new GsViewModel());
}();
我收到的错误:
消息:无法处理绑定“event:function(){return {change:setschema}}”
消息:尚未定义setschema
由于
答案 0 :(得分:1)
只需进行一次简单的更改,您只需设置setschema
eventschemacondition().setschema
,因为setschema
不在getdetails
的正下方。
查看:
<select data-bind="options: eventschemas, optionsText: 'schema', value:eventschemacondition().schema, event: {change:eventschemacondition().setschema}"></select>
工作小提琴here