Knockout.js DDL更改事件

时间:2014-01-14 19:38:59

标签: knockout.js

任何人都知道在更改活动时如何传递整个对象。

查看:

<select data-bind="foreach: controlConfig, event: { change: selectionChanged }, value: $data">
  <option data-bind="text: $data.Name"></option>
</select>

视图模型:

self.selectionChanged = function (data, event) {
            alert("the other selection changed " + data.Name);
        }

1 个答案:

答案 0 :(得分:0)

1.对于select元素应使用特殊绑定 - options

<select data-bind="options: controlConfig, value: selectedConfig"></select>

2.要在下拉列表中处理选择项目,您需要使用the value binding绑定所选值“selectedConfig”然后订阅它:

function ViewModel() {
    var self = this;
    self.controlConfig = ko.observableArray();
    self.selectedConfig = ko.observable();
    self.selectedConfig.subscribe(function(newVal) {
        // your code here...
    }); 
}

请检查此SO Question