Dynamically add js object to model array in 1.13

后端 未结 3 1897
无人及你
无人及你 2021-02-18 21:11

I have the following code:

var msg = this.store.createRecord({text:\'first title\', createdAt: \"2015-06-22T20:06:06+03:00\" })

this.get(\'model.content\').push         


        
相关标签:
3条回答
  • 2021-02-18 21:34

    I would make all return models to array then, add array to this array

    setPeople:function(){
        this.set('people',this.get('content').toArray())
    }.observes('content')
    

    then, find more person models, to array

    getMoreUsers(){
          var self = this;
                this.set('offset', this.get('offset')+1);
                self.store.findAll('person').then(function(people){
                 self.get('people').pushObjects(people.toArray());
                });
    
    0 讨论(0)
  • 2021-02-18 21:38

    Before 1.13:

    this.get('content').pushObjects(messages);
    

    After 1.13:

    messages.forEach(functio(message) {
      this.get('model.content').pushObject(message._internalModel);
    }); 
    
    0 讨论(0)
  • 2021-02-18 21:43

    One possible solution without resorting to private API is to use toArray() (github issue):

    var array = this.get('messages').toArray()
    array.addObjects(this.get('messages'))
    array.addObject(msg)
    this.set('messages', array)
    
    0 讨论(0)
提交回复
热议问题