我正在使用 materialize css 库,它说
Collapsible elements only need initialization if they are added dynamically
然后我动态地添加了一些元素。所以在呈现 View 后我应该运行这个函数:
$('.collapsible').collapsible({
accordion : false
});
在 setupController
函数中,我发出一些请求,并在每个请求完成后设置 Controller 。当 Controller 获取模型并在使用新模型数据呈现 View 后,我应该运行一个函数来初始化 ui 元素
最佳答案
您必须为 Accordion 设置一个 ember.js 组件并使用 didInsertElement Hook :
export default Ember.Component.extend({
classNames: ['.collapsible'],
didInsertElement() {
Ember.run.scheduleOnce('afterRender', this, function() {
this.$().collapsible({
accordion: false
});
});
},
});
关于javascript - Ember js 如何在模型更改后运行函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37940673/