请帮我解决knockout.js问题:
为什么变量 currentObject 未定义?如何将当前选定的对象保存在某个变量中?
我已经关注下拉列表的 html 视图:
<select data-placeholder="Select object" class="span5" id="objects" data-bind="options: objects, optionsText: 'Name', optionsValue: 'Id', value: currentObject">
<option></option>
</select>
模型视图:
function baseViewModel() {
self.objects = ko.observableArray([]);
...
self.currentObject = ko.observable();
...
self.func = function() {
//allert(self.objects()[0].Name) //return correct Name
alert(self.currentObject().Name) //returns undefinded
}
}