2015-09-30 39 views
0

我有這個posts.hbs灰燼2,model.save()從組件MY-modal.hbs

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

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

然後我打開我的寫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> 
現在

,這是我的組件/寫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

{{outlet}} 

{{outlet "modal"}} 

最後modal.hbs

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

但我

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

得到這個錯誤:「Uncaught TypeError:無法讀取屬性「保存」的未定義「

如何解決這個問題?

回答

0

您發送 「POST」 記錄作爲參數

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

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

這是餘燼記錄。然後,你想找到完全一樣的POST

而不是使用的(U需要指定 「目錄/ MODEL_NAME」 沒有DS記錄實例)

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

使用

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

不當然,如果這有助於你的問題,讓我知道。