2017-04-27 92 views
0

一個特性,這是我的代碼,其是不工作knockout.js ko.mapping.fromjs包括在結合

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」:假 「listremove」:假 「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}]}]

如何在綁定中僅包含cardlist?

如何在綁定中排除showRenderTimes?

回答

1

使用include關鍵字只能添加任何性質你原來的對象不已經一部分。

通過使用ignore關鍵字,您可以指定您不想映射的對象的那些屬性。

所以在你的情況下,你可以指定你不想成爲映射的一部分的所有屬性,只有cardlists離開那裏。

'忽略'

var mapping = { 
    'ignore': ["boardid", "boardname","listid","cardvisiblity","showlist","listremove","showRenderTimes"] 
} 
ko.mapping.fromJS(data, mapping, self.lists); 
+0

忽視的手段,例如,如果cardvisiblity是假它將保持假的?如果它來了,它不會受到影響 – maztt

+0

不,這意味着如果'cardvisiblity'是你的對象的一部分,你告訴映射插件忽略映射的這個屬性。它不會成爲綁定模型的一部分。 –

+0

cardvisiblity不會成爲self.lists的一部分嗎? – maztt