【发布时间】:2012-06-04 15:08:54
【问题描述】:
我在映射 WCF 返回的 json 对象时遇到问题。 wcf 返回一个 PaidPeople 类的列表,而 jSon 返回看起来像
[Object { __type="PaidPeople:#model", Amount=110, Attendee=1, more...}, more...]
我还 JSON.stringify 返回对象,我得到一个数组
[
{"__type":"PaidPeople:#model","Amount":110,"Attendee":1,"CashPay":1,"DtPaid":"/Date(1338102000000-0700)/","Name":"John Doe"}, more
]
我的问题是将它映射到我的视图
这里是代码
var PayinyVM = {};
$.getJSON('/service/PaidService.svc/PaidList', function (data) {
var tmp = JSON.stringify(data.d);
PayinyVM.model = ko.mapping.fromJSON(tmp);
ko.applyBindings(PayinyVM);
}); //getJSON
HTML 看起来像:
<div data-bind="foreach: ????">
<h3 data-bind="text: Name">
</h3>
<p>
Name: <span data-bind="text: Name"></span>
</p>
</div>
在长时间的 jquery 代码之后,我刚刚开始使用淘汰赛进行编码,并且非常喜欢它,但是我错过了很多练习。任何帮助将不胜感激
【问题讨论】:
标签: knockout.js knockout-mapping-plugin