当前位置: 动力学知识库 > 问答 > 编程问答 >

ember.js - EmberJS - add actions programatically

问题描述:

I am creating a file menu like this using Ember:

{{file-menu menuItems=model.fileMenu.menuItems}}

file-menu.hbs:

<ul class="nav navbar-nav">

{{#each menuItems as |item|}}

{{component item.type item=item}}

{{/each}}

</ul>

Then in my router I am constructing the menu like so:

var fileMenu = FileMenu.create();

var orderButton = MenuButton.create({name:"Place Order"});

var fileMenuItem = MenuItem.create({name:"File"});

fileMenuItem.addSubItem(MenuItem.create({name:"Save"}));

fileMenuItem.addSubItem(MenuItem.create({name:"Load"}));

fileMenu.addMenuItem(fileMenuItem);

fileMenu.addMenuItem(MenuItem.create({name:"Edit"}));

fileMenu.addMenuItem(MenuItem.create({name:"Help"}));

fileMenu.addMenuItem(MenuButton.create(orderButton);

Now I want to programmatically add an action to my orderButton for when it is clicked. However, I am not sure how to do this. I could only find info on doing it from the template. Is it possible to add actions programmatically and is it acceptable to do that?

分享给朋友:
您可能感兴趣的文章:
随机阅读: