Ember 2.0 - 页面浏览量
Ember 2.0 - views for pages
我习惯于在我为页面创建的视图文件中放置一些 jquery 代码。
例如:
- 我有路线
this.route('buildings');
接下来创建视图文件app/views/buildings.js
import Ember from "ember";
export default Ember.View.extend(Ember.TargetActionSupport, {
didInsertElement: function () {
//jquery here
}
});
但是现在Ember2.0就没有这个能力了,怎么办?
放在组件中。在components/my-component.js
import Ember from 'ember';
export default Ember.Component.extend({
didInsertElement: function(){
// jquery here.
}
});
在您的模板中:
{{my-component}}
或者:
{{#my-component}}
Stuff
{{/my-component}}
在 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');
}
});
请参阅此 jsbin 以获取工作示例。
P.S。罗伯特·杰克逊的评论:"Using a component as ApplicationView will allow customization of classNames and whatnot, but is definitely going to have a number of negative results as well (for example controller is not correct)." https://github.com/emberjs/ember.js/issues/11486#issuecomment-131366332
我习惯于在我为页面创建的视图文件中放置一些 jquery 代码。
例如:
- 我有路线
this.route('buildings');
接下来创建视图文件app/views/buildings.js
import Ember from "ember"; export default Ember.View.extend(Ember.TargetActionSupport, { didInsertElement: function () { //jquery here } });
但是现在Ember2.0就没有这个能力了,怎么办?
放在组件中。在components/my-component.js
import Ember from 'ember';
export default Ember.Component.extend({
didInsertElement: function(){
// jquery here.
}
});
在您的模板中:
{{my-component}}
或者:
{{#my-component}}
Stuff
{{/my-component}}
在 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');
}
});
请参阅此 jsbin 以获取工作示例。
P.S。罗伯特·杰克逊的评论:"Using a component as ApplicationView will allow customization of classNames and whatnot, but is definitely going to have a number of negative results as well (for example controller is not correct)." https://github.com/emberjs/ember.js/issues/11486#issuecomment-131366332