1

そのため、デフォルトとは異なるコントローラーで計算されたプロパティを使用すると問題が発生します。

私はこのモデルを持っています:

export default DS.Model.extend({
    firstName:       DS.attr('string'),
    lastName:        DS.attr('string'),
    email:           DS.attr('string'),
    emailOptIn:      DS.attr('boolean'),
    emailVerified:   DS.attr('boolean'),
    receivedWelcome: DS.attr('boolean'),

    locations:            DS.hasMany('location'),
    serviceRelationships: DS.hasMany('service-relationship'),
    phoneNumbers:         DS.hasMany('phone-number'),

    fullName: function(){
        return this.get('firstName') + ' ' + this.get('lastName');
    }.property('firstName', 'lastName')
});

どちらが入っていますかcontact.js(ember-cli を使用しています)。

次に、このコントローラーがあります:

var NavBarController = Ember.Controller.extend({
    fullName: '',
    init: function(){
        var contactId = this.session.contactId;
        var self = this;
        this.store.find('contact', contactId).then(function(contact){
            self.set('fullName', contact.get('fullName'));
        });
})

export default NavBarController;

テンプレートには何も表示されません。ただし、次のように変更すると:

    fullName: '',
    init: function(){
        var contactId = this.session.contactId;
        var self = this;
        this.store.find('contact', contactId).then(function(contact){
            window.setTimeout(function(){
                self.set('fullName', contact.get('fullName'));
            }, 100);
        });
})

{{fullName}}次に、ハンドルバーをうまくレンダリングします。

質問:thenのない関数で解決されないのはなぜtimeoutですか?

4

0 に答える 0