0
我遇到了將JSON從ASP.net webform webapi綁定到具有KnockoutJs的視圖模型的問題。 wepapi沒有問題,並且映射到mappedQuickEntries。KnockoutJs將JSON映射到視圖模型
我在哪裏弄錯了?謝謝。
錯誤:
Error: Unable to parse bindings. Message: ReferenceError: ItemPartNumb is not defined; Bindings value: value: ItemPartNumb
查看:
<div>
<table border="1" cellpadding="0" cellspacing="0">
<tbody data-bind="foreach: quickEntries">
<tr>
<td data-bind="value: ItemPartNumb"></td>
<td data-bind="value: ItemDescription"></td>
</tr>
</tbody>
</table>
視圖模型:
<script type="text/javascript">
var QuickEntry = function(_itemPartNumb, _itemDescription) {
this.ItemPartNumber = ko.observable(_itemPartNumb);
this.ItemDescription = ko.observable(_itemDescription);
};
function QuickEntriesViewModel() {
var self = this;
self.quickEntries = ko.observableArray([]);
$.ajax({
url: '/DesktopModules/Blah/API/Data/GetTenQuickEntries',
type: 'GET',
dataType: 'json',
success: function (data) {
var mappedQuickEntries = $.map(data, function (item) {
return new QuickEntry(item.ItemPartNumb, item.ItemDescription);
});
self.quickEntries(mappedQuickEntries);
},
statusCode: {
404: function() {
alert('Failed');
}
}
});
};
ko.applyBindings(new QuickEntriesViewModel());
嘿謝謝指出。我做了改變。但是,該表沒有創建,現在我沒有錯誤消息。 – Jack