简体   繁体   中英

ng-repeat not tracking old key-pair value

I've json like this..

var storedData = {  
 "Feb 7, 2017":[  
   {  
     "emMessageId":1019,
     "message":"HI",
     "userId":100166,
     "imHashTagId":null,
     "taggedUser":null,
     "iconPath":"i",
     "sendMsgDate":1486469494000
   },
   {....}
 ],
"Feb 8, 2017":[  
  {  
     "emMessageId":1090,
     "message":"hi",
     "userId":100165,
     "imHashTagId":null,
     "taggedUser":null,
     "iconPath":"i",
     "sendMsgDate":1486495671000
  },
  {....}
 ]
}

now i'm adding more data to "today" key like..

 if(!storedData['Today'])
   storedData['Today'] = [{new obj}]
 else
    storedData['Today'].push({new obj});

It's adding fine but "ng-repeat" not tracking old key-pairs value.Please help me Expert's, Thanks in advance.

Plunker Demo: https://plnkr.co/edit/YHQhC0Qibbrr5fD73fGr?p=info

The issue here was that ng-repeat , when adding a new item to self.storedData['Today'] , is processing just that last added item.

Here is the plunker link that does what you want. Basically I have added a temporary array self.todayItems and when Send button is clicked, just do self.storedData['Today'] = angular.copy(self.todayItems); , which creates a copy of the entire array. Since a new array is added, all items in that array are re-evaluated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM