Ember template not updating from arraycontroller

前端 未结 1 1005
时光取名叫无心
时光取名叫无心 2020-12-18 16:28

In my app, a user can enter a description of a friend or upvote a description that is already present. Both methods (createDescription and upvoteDescription) persist in the

相关标签:
1条回答
  • 2020-12-18 16:31

    find (by query) doesn't actively make sure it has the records that match the query, so you'll have to manually inject it into the results.

    createDescription: function () {
      var name = this.get('name'),
          friend_id = this.get('controllers.friend').get('id'),
          store = this.get('store'),
          description = store.createRecord('description', {
            name: name,
            friend_id: friend_id
          });
      description.save();
      this.pushObject(description);
    },
    

    or you can use a live record array (filter/all)

      model: function () {
        var store = this.get('store'),
            friend = this.modelFor('friend');
        store.find('description', {friend_id: friend.id});
        return store.filter('description', function(record){ 
           return record.get('friend_id') == friend.id;
        });
      }
    
    0 讨论(0)
提交回复
热议问题