我正在努力让X-editable与knockout一起工作,以下是我的代码
$(document).ready(function () {
var viewModel = function () {
var self = this;
self.id = ko.observable();
self.firstName = ko.observable();
self.lastName = ko.observable();
self.gender = ko.observable();
self.genders = ko.observableArray();
self.firstName = ko.observable('John');
self.lastName = ko.observable('Doe');
self.gender = ko.observable('Male');
self.genders.push("Male");
self.genders.push("Female");
}
ko.applyBindings(viewModel);
EditableManager.registerEditable();
EditableManager.onSuccess = function (result) {
};
这是我的HTML,
<span data-bind="editable: gender, editableOptions: {pk: id, options: genders, optionsText: 'text', optionsValue: 'id'}"></span>
我收到了异常
未捕获的TypeError:无法处理绑定“
editable: function (){return gender }
” 消息:无法读取未定义的属性“length
”
我是Knockout和x-editable的新手,任何人都可以提供帮助,对此非常感谢。
答案 0 :(得分:0)
正如nemesv所说,我还没有新的,
在ko.applyBindings(viewModel)中缺少new;它应该是ko.applyBindings(new viewModel());