Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 在1.13中动态地将js对象添加到模型数组中_Ember.js_Ember Data - Fatal编程技术网

Ember.js 在1.13中动态地将js对象添加到模型数组中

Ember.js 在1.13中动态地将js对象添加到模型数组中,ember.js,ember-data,Ember.js,Ember Data,我有以下代码: var msg = this.store.createRecord({text:'first title', createdAt: "2015-06-22T20:06:06+03:00" }) this.get('model.content').pushObject(msg); msg.save(); 我们创造了新的记录。然后将其推入模型以显示。它在1.9版本中工作得很好,但升级到最新的1.13版本后,它出现故障并显示此错误: TypeError:internalModel

我有以下代码:

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

this.get('model.content').pushObject(msg);

msg.save();
我们创造了新的记录。然后将其推入模型以显示。它在1.9版本中工作得很好,但升级到最新的1.13版本后,它出现故障并显示此错误:

TypeError:internalModel.getRecord不是函数

经过一些研究,我得出了这个解决方案

this.get('messages.content').unshiftObject(message.internalModel);
这也有一定的帮助。现在我有两个问题:

  • 我不确定使用私有的ember数据api是否是一个好主意
  • 在将记录添加到模型和 在屏幕上渲染它。如果我不打电话,那就更糟了 msg.save();该记录未呈现。据我所知 等待服务器的响应,然后才呈现它。 但我需要相反的行为——我需要先展示记录,然后 然后保存它(显示用户的保存状态),方法如下 认为一切都进展得非常快

    • 一种不使用私有API的可能解决方案是使用
      toArray()
      ():

      1.13之前:

      this.get('content').pushObjects(messages);
      
      1.13之后:

      messages.forEach(functio(message) {
        this.get('model.content').pushObject(message._internalModel);
      }); 
      

      我会把所有的返回模型放到数组中,然后把数组添加到这个数组中

      setPeople:function(){
          this.set('people',this.get('content').toArray())
      }.observes('content')
      
      然后,找到更多的人物模型,进行排列

      getMoreUsers(){
            var self = this;
                  this.set('offset', this.get('offset')+1);
                  self.store.findAll('person').then(function(people){
                   self.get('people').pushObjects(people.toArray());
                  });
      

      这里的模型和内容是什么?您使用的是1.13.x,其中x表示余烬和余烬数据?是的,余烬1.13.2和余烬数据1.13.4与余烬有完全相同的问题:“1.13.3”,“余烬数据”:“1.13.5”,
      getMoreUsers(){
            var self = this;
                  this.set('offset', this.get('offset')+1);
                  self.store.findAll('person').then(function(people){
                   self.get('people').pushObjects(people.toArray());
                  });