0

我有这个posts.hbs

{{#each model as |post|}}
    <a href="#" {{action 'openWriteModal' post}}>

      <h3>{{post.title}}</h3>
          {{post.text}}
          {{post.author.name}}
    </a>
{{/each}}

然后我打开我的write-modal.hbs

{{input value=model.title size="40" escape-press='close'}}

{{model.author.name}}

{{input value=model.text size="70" escape-press='close'}}

<button {{action 'close'}}>Close</button>
<button {{action 'save' model}}>Save</button>

现在,这是我的components/write-modal.js

export default Ember.Component.extend({

  actions: {

    close: function() {
      return this.sendAction('close');
    },

    save(model) {
        model.set("text", model.get("text"));
        model.save().then(this.sendAction('close'));
    }
  }
});

这是posts.js

export default Ember.Route.extend({

    model() {
        return this.store.findAll('post');
    },

  actions: {
    openWriteModal(post) {

      return this.render('modal', {
        outlet: 'modal',
        into: 'application',
        model: this.store.findRecord('post', post.id, { reload: true }),
        controller: 'application'
      });
    },

    closeWriteModal() {

      return this.disconnectOutlet({
        outlet: 'modal',
        parentView: 'application'
      });
    },

    saveWriteModal(model) {

      model.save();
},

......

  model(params) {
    return this.store.query('post', params);
  }

});

在我的application.hbs中:

{{outlet}}

{{outlet "modal"}}

最后是 modal.hbs

{{write-modal model=model close='closeWriteModal' save='saveWriteModal'}}

但我收到此错误:“未捕获的类型错误:无法读取未定义的属性‘保存’”

如何解决这个问题?

4

1 回答 1

0

您正在发送“POST”记录作为参数

{{#each model as |post|}}
    <a href="#" {{action 'openWriteModal' "----post----"}}>  

      <h3>{{post.title}}</h3>
          {{post.text}}
          {{post.author.name}}
    </a>
{{/each}}

这是一张灰烬唱片。然后你试图找到完全相同的 POST

而不是使用(您需要指定“目录/模型名称”而不是 DS 记录实例)

 model: this.store.findRecord('post', post.id, { reload: true }), 

利用

return this.render('modal', {
    outlet: 'modal',
    into: 'application',
    model: post
    controller: 'application'
  });

不确定这是否对您的问题有帮助,请告诉我。

于 2015-09-30T18:38:02.147 回答