我习惯于在视图文件中放置一些jquery代码,这些代码是我为页面创建的。
例如:
this.route('buildings');
但是现在对于Ember 2.0我们没有这样的能力,我该怎么办?
发布于 2015-08-14 15:02:06
在Ember 2.0.0中,仍然可以执行以下操作:
App.ApplicationView = Ember.Component.extend({
classNames: ['customClassName'],
didInsertElement: function() {
alert('did insert element')
}
});
App.BuildingsView = Ember.Component.extend({
classNames: ['customClassName2'],
didInsertElement: function() {
alert('did insert element2');
}
});
有关工作示例,请参阅此吉斯宾。
P.S. Robert的评论:“使用组件作为ApplicationView将允许定制classNames和诸如此类的东西,但肯定也会产生许多负面结果(例如控制器不正确)。”
发布于 2015-08-14 13:31:04
把它放进组件里。在components/my-component.js中
import Ember from 'ember';
export default Ember.Component.extend({
didInsertElement: function(){
// jquery here.
}
});
在模板中:
{{my-component}}
或者:
{{#my-component}}
Stuff
{{/my-component}}
https://stackoverflow.com/questions/32011237
复制相似问题