如何解决Ember defineProperty 不反映在模板上,直到调用 notifyProperty 更改?
我基本上有一个功能标志,它被添加到用户保存配置的列表中。保存时,我在服务对象上创建了一个计算属性,如下所示。
//classify() just removes the '_' and Makes it title case 'add_location' --> 'AddLocation'
defineFeature(feature) {
defineProperty(this,`is${classify(feature)}`,computed('session.account.features.[]',function() {
return this.hasFeature(feature);
}));
},
现在这在服务对象上设置属性,我在我的 .hbs 文件中使用它。但是它不会反映,除非我触发 <serviceObj>.notifyPropertyChange('is<FlagName');
我很困惑为什么 Ember 不会自行更新,或者我做错了什么?
添加更多上下文
我的处理程序文件
{{#if featureService.isAddLocation}}
<span>User can now add locations for this account</span>
{{/if}}
组件文件
一个基本上切换标志的保存功能。
onSave() {
// This method is called on user action
let account = get(this,'account');
account.enableSaveLocation().then(() => {
account.reload().then(() => {
// basically only after the save the feature 'add_location' gets added to
// the features array in the 'account' model
featureService.defineFeature('add_location');
//featureService.notifyPropertyChange('isAddLocation'); // Without this line the template doesnt reflect the change
})
})
}
Ember: v3.4
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。