在EmberJs中查看特定的JavaScript代码重用
假设在渲染视图时,有两个不同的视图包含相同的视图逻辑 我在didInsertElement回调中放入了我的逻辑两次 EmberJS中是否有避免视图逻辑代码重复的最佳实践在EmberJs中查看特定的JavaScript代码重用,javascript,jquery,ember.js,Javascript,Jquery,Ember.js,假设在渲染视图时,有两个不同的视图包含相同的视图逻辑 我在didInsertElement回调中放入了我的逻辑两次 EmberJS中是否有避免视图逻辑代码重复的最佳实践 期待您的回答。您应该熟悉继承 也就是说,这可能是您的解决方案: App.MyBaseView = Ember.View.extend({ onDidInsert: function(){ // shared logic }.on('didInsertElement') }); App.Firs
期待您的回答。您应该熟悉继承 也就是说,这可能是您的解决方案:
App.MyBaseView = Ember.View.extend({
onDidInsert: function(){
// shared logic
}.on('didInsertElement')
});
App.FirstSpecificView = App.MyBaseView.extend({
onDidInsert: function(){
// this views specific logic
}.on('didInsertElement')
});
App.SecondSpecificView = App.MyBaseView.extend({
onDidInsert: function(){
// this views specific logic
}.on('didInsertElement')
});
您将创建一个实现基本逻辑的基本视图,并用特定逻辑扩展该视图。使用.on('diInsertElement')的目的是什么?如果我们只使用“didInsertElement”而不是onDidInsert,有什么区别?