如何将 ember 3.4 组件属性结合 'computed' 和 'on()'
how to have ember 3.4 component properties combining 'computed' and 'on()'
我们的 ember 2.9.0 项目中的代码具有如下属性的组件:
hide: on("init", computed("hasEnoughData", function () {
return !this.hasEnoughData;
})),
当我将它迁移到 ember 3.4 时,它因以下错误而中断:
Assertion Failed: on expects function as last argument
基本上,on()
函数期望最后一个参数是一个函数。此代码用于与 2.9 结合使用 computed
和 on()
.
在 ember 3.4 中有推荐的方法吗?
当 init 中有很多其他代码 运行 时,有时需要这种对 init 钩子的依赖。这是我的做法,尽管可能还有其他方法。代码示例是 Ember 3.x.
init() {
this._super(...arguments)
// some processing code that takes time
this.set(‘shouldShowElement’, true)
},
hide: computed("hasEnoughData", “shouldShowElement”, function () {
return !this.hasEnoughData && !shouldShowElement;
})),
我们的 ember 2.9.0 项目中的代码具有如下属性的组件:
hide: on("init", computed("hasEnoughData", function () {
return !this.hasEnoughData;
})),
当我将它迁移到 ember 3.4 时,它因以下错误而中断:
Assertion Failed: on expects function as last argument
基本上,on()
函数期望最后一个参数是一个函数。此代码用于与 2.9 结合使用 computed
和 on()
.
在 ember 3.4 中有推荐的方法吗?
当 init 中有很多其他代码 运行 时,有时需要这种对 init 钩子的依赖。这是我的做法,尽管可能还有其他方法。代码示例是 Ember 3.x.
init() {
this._super(...arguments)
// some processing code that takes time
this.set(‘shouldShowElement’, true)
},
hide: computed("hasEnoughData", “shouldShowElement”, function () {
return !this.hasEnoughData && !shouldShowElement;
})),