Javascript arrays and Meteor session

后端 未结 2 1954
慢半拍i
慢半拍i 2021-02-20 08:57

I have made an interesting observation. When trying to update an array that is stored in the Meteor session storage, the following code will not propagate the changes:



        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-20 09:21

    I believe this is the same as this situation in Backbone.js. In order for the change event to be triggered, Meteor needs to have a new reference for the array, not just an updated copy of the old one.

    In brief, in order to have the 'correct' behaviour, you'll need to clone the array, make the changes you want, and then do Session.set('foo', myCopiedArray).

提交回复
热议问题