我试图理解淘汰赛的语法并遇到问题。
我的 ko 视图模型示例
var Market = function (e) {
var self = this;
self.MarketId = ko.observable(e ? e.MarketId : '');
self.Description = ko.observable(e ? e.Description : '');
};
var MarketAddViewModel = function () {
var self = this;
var url = "/api/market";
self.newMarket = ko.observable(new Market());
// Save market
saveMarket = function (item) {
$.ajax({
type: 'POST',
url: url,
data: ko.toJS(item),
success: function (data) {
// SUCCESS
},
error: function (err) {
var err = JSON.parse(err.responseText);
var errors = "";
for (var key in err) {
if (err.hasOwnProperty(key)) {
errors += key.replace("employee.", "") + " : " + err[key];
}
}
alert('error');
//$("<div></div>").html(errors).dialog({ modal: true, title: JSON.parse(err.responseText).Message, buttons: { "Ok": function () { $(this).dialog("close"); } } }).show();
},
complete: function () {
// complete
}
});
};
};
要绑定它,我使用此代码
$(document).ready(function () {
ko.applyBindings(new MarketAddViewModel());
});
然后是 HTML 元素
<input data-bind="value: Description" type="text" class="required input-xxlarge" name="description" id="description" />
但是当加载此页面时,我收到“未定义描述”
有什么线索吗?