Javascript 使用ember引导在EmberJS应用程序中创建Twitter引导模式
按照指南,以编程方式创建模式对话框Javascript 使用ember引导在EmberJS应用程序中创建Twitter引导模式,javascript,twitter-bootstrap,ember.js,controller,bootstrap-for-ember,Javascript,Twitter Bootstrap,Ember.js,Controller,Bootstrap For Ember,按照指南,以编程方式创建模式对话框 <h1 class="page-header">Welcome!</h1> {{bs-button title="Create Modal" clicked="createModalProgramatically"}} 我想扩展ApplicationController(而不是index controller),因为我希望能够以编程方式从应用程序中的任何位置调用模式对话框 我如何在不在每个我想使用模态的控制器上重复模态代码的情况下实
<h1 class="page-header">Welcome!</h1>
{{bs-button title="Create Modal" clicked="createModalProgramatically"}}
我想扩展ApplicationController(而不是index controller),因为我希望能够以编程方式从应用程序中的任何位置调用模式对话框
我如何在不在每个我想使用模态的控制器上重复模态代码的情况下实现这一点
我错过了什么?谢谢 您可以将引导代码放入控制器,如
MyBootstrapController
:
MyEmberApp.MyBootstrapController = Ember.Controller.extend({
manualButtons: [
Ember.Object.create({title: 'Submit', clicked:"submitManual"}),
Ember.Object.create({title: 'Cancel', dismiss: 'modal'})
],
actions: {
submitManual: function() {
Bootstrap.NM.push('Modal destroyed!', 'success');
return Bootstrap.ModalManager.close('manualModal');
},
createModalProgramatically: function() {
Bootstrap.ModalManager.open('manualModal', 'Hello', 'index', this.manualButtons, this);
}
}
});
然后使所有下一个要从MyBootstrapController
继承的控制器如下:
MyEmberApp.IndexController = MyEmberApp.MyBootstrapController.extend({
// Some other controller stuff
});
这是一个利用mixin的绝佳机会!查看文档,但实际上您所需要做的只是获取该代码并为其进行混合,然后在任何您想要使用该代码的地方,您都可以通过将其作为扩展的属性传入来导入它。试一试,如果你需要一个JSBIN来演示,请告诉我。
MyEmberApp.IndexController = MyEmberApp.MyBootstrapController.extend({
// Some other controller stuff
});