[英]Bind function on template creation in Ember.js
I have a Handlebars template that needs to have a javascript function run on its creation. 我有一个Handlebars模板,需要在其创建时运行javascript函数。 Is this possible in Ember/handlebars? 这在Ember /车把中可行吗? Specifically, it is a partial that creates a "status bar" with a percentage and a certain amount of the bar filled up. 具体来说,它是一个部分,它创建了一个“状态栏”,状态栏填充了一定百分比和一定量的栏。 I already have a working function for this, I just need a way to have it run for all the status bars (there are many on the page) when they load. 我已经有了一个有效的功能,我只需要一种在加载所有状态栏(页面上有很多状态栏)时运行它的方法。
I would wrap your progress bars in an ember component. 我会将您的进度条包装在ember组件中。 Then use didInsertElement
to trigger your function. 然后使用didInsertElement
触发您的函数。 Additionally you could scope to that particular progress bar instance. 另外,您可以将范围限定在该特定进度条实例上。
App.ProgressBarComponent = Em.Component.extend({
someFunc: function(){
this.myFunc();
}.on('didInsertElement'),
myFunc: function(){
console.log('this component is', this.$());
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.