私がやっていることは、モデルデータをテンプレートにレンダリングすることです。 モデルフックを設定すると、{{model}}オブジェクトは対応するテンプレートのデータを表示しません。 ここに私のコードです:Ember:モデルフックルートにストアでモデルが設定されていません
接触(ルート):
user: Ember.inject.service('current-user'),
model: function()
{
// var that = this;
// console.log('whats being returned bitch: ', this.store.findRecord('contact', this.get('user').contactID));
//return this.store.findRecord('contact', this.get('user').contactID);
var records = this.store.findRecord('contact', this.get('user').contactID);
var promise = Ember.RSVP.defer();
// console.log('promise', promise.resolve());
// records.addObserver('isLoaded', function() {
// // console.log('records.getv', records);
promise.resolve(records);
//});
return promise;
},
setupController: function(controller)
{
// Get the parameters for the current route every time as they might change from one record to another
var params = this.paramsFor('dashboard.contact');
console.log('params', params);
// Set the data in the current instance of the object, this is required. Unless this is done the route will display the same data every time
this.module = Ember.String.capitalize(params.module);
this.id = params.id;
this.data = this.store.find(this.module,this.id);
// Set the data in the controller so that any data bound in the view can get re-rendered
controller.set('id',this.id);
controller.set('model',this.data);
controller.set('module',this.module);
}
});
まず私はちょうどthisをしようとしていたが、それはデータを表示していなかった、それから私は(thisのような)約束を延期し、それを解決しようとしたし、最終的に私コントローラ(setupController機能)を設定しようとしたが、それはうまくいきませんでしたどちらかのparamsので、何らかの理由で空になる:/
接触(テンプレート):
<h1> Contact! </h1>
{{#each model as |contact|}}
<h3>{{contact.name}}</h3>
<h3>{{contact.password_c}}</h3>
{{/each}}
接触(モデル):
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
password_c: DS.attr('string'),
birthdate: DS.attr('string'),
assistant: DS.attr('string'),
account_name: DS.attr('string'),
email1: DS.attr('string'),
facebook: DS.attr('string'),
phone_home:DS.attr('string')
// address: Ember.computed('primary_address_street', 'primary_address_state',
// 'primary_address_city', 'primary_address_country', function() {
// return '${this.get('primary_address_street')} ${this.get('primary_address_state')} ${this.get('primary_address_city')} ${this.get('primary_address_country')}';
// })
});
助けてください!
あなたは連絡先を表示したいが、 'setupController'には何か他のものが返されます。また、set/getのために 'set''get'メソッドを使う必要があります。また、すべてのモデルは 'model'フックでフェッチされるべきです。 'setupController'はデータを取得するのには適していません。 'model'フックにも' params'パラメータがあります。 –
ですので、基本的にはsetupController関数を削除していますか? –
はい。あなたのケースでは必要ありません。 –