这是我的代码无效
var getUpdates = setInterval(function () {
$.getJSON("@Url.Action("GetLists", "Home")?id=" + self.selectedboard(), function (data) {
var mapping = {
// only include these two properties
'include': ["cardlists"]
}
ko.mapping.fromJS(data, mapping, self.lists);
ko.applyBindings(helloWorldModel);
});
}, 3000);
数据正在返回
[{ “板卡ID”:1, “boardname”: “asdasd”, “listid”:15, “LISTNAME”: “asdasd”, “cardvisiblity”:真 “showlist”:假 “listremove”:假“showRenderTimes”:假 “cardlists”:[{ “CardId中”:23, “cardname”: “7”, “listid”:15},{ “CardId中”:24, “cardname”: “3”,” listid “:15},{” CardId中 “:27,” cardname “:” asdasd”, “listid”:15},{ “CardId中”:38, “cardname”: “asdasd”, “listid”:15}] },{ “板卡ID”:1, “boardname”: “asdasd”, “listid”:22, “LISTNAME”: “asdasd”, “cardvisiblity”:真 “showlist”:假 “listremove”:假” showRenderTimes “:假” cardlists “:[{” CardId中 “:33,” cardname “:” asdasd”, “listid”:22},{ “CardId中”:39, “cardname”: “asdasd”, “listid” :22},{ “CardId中”:41, “cardname”: “qdasd”, “listid”:22}]},{ “板卡ID”:1, “boardname”: “asdasd”, “listid”:23,” LISTNAME “:” asdasd”, “cardvisiblity”:真 “showlist”:假 “listremove”:假 “showRenderTimes”:假 “cardlists”:[{ “CardId中”:34, “cardname”: “asdasd” “listid”:23},{ “CardId中”:40 “cardname”: “asdasd”, “listid”:23}]},{ “板卡ID”:1, “boardname”: “asdasd”, “listid” :24, “LISTNAME”: “asdasd”, “cardvisiblity”:真实的, “showlist”:假的,“李stremove “:假” showRenderTimes “:假” cardlists “:[{” CardId中 “:35,” cardname “:” qweqwe “ ”listid“:24},{ ”CardId中“:36, ”cardname“:” asdasd”, “listid”:24},{ “CardId中”:37, “cardname”: “asdasd”, “listid”:24},{ “CardId中”:42, “cardname”: “sdfsdf”, “listid” :24},{ “CardId中”:43, “cardname”: “asdasd”, “listid”:24}]}]
如何仅在绑定中包含卡片表?
如何在绑定中排除showRenderTimes?
答案 0 :(得分:1)
使用include
关键字,您只能添加 已经原始对象的任何属性。
使用ignore
关键字,您可以指定您不想要映射的对象的属性。
因此,在您的情况下,您可以指定您不希望成为映射一部分的所有属性,并且只留下cardlists
。
<强>&#39;忽略&#39; 强>
var mapping = {
'ignore': ["boardid", "boardname","listid","cardvisiblity","showlist","listremove","showRenderTimes"]
}
ko.mapping.fromJS(data, mapping, self.lists);