特点: 添加新的“标签”后,可以将警报事件视为默认事件。
点子:
TabsController
initilizerView
并使用list参数来处理TabsController.Content
function ( "didInsertElement" )
请帮助
的jsfiddle http://jsfiddle.net/chalien/Hxste/2/
由pangratz解决 感谢您的帮助和重构:)
答案 0 :(得分:1)
您可以使用action
句柄助手,请参阅http://jsfiddle.net/jmDXP/
<强>车把:强>
<script type="text/x-handlebars" id="mainview" >
{{#each list}}
<div {{action "clicked"}} >{{title}} / {{desc}}</div>
{{/each}}
</script>
<script type="text/x-handlebars" >
<div id="container"></div>
{{#view App.TabView}}
{{view Ember.TextField valueBinding="title"}}
{{view Ember.TextField valueBinding="desc"}}
<button {{action "addTab" }} >Add</button>
{{/view}}
</script>
<强> JavaScript的:强>
var get = Ember.get;
App = Ember.Application.create({});
App.Tab = Ember.Object.extend({
title: null,
desc: null
});
App.TabsController = Ember.ArrayController.create({
content: [],
resourceType: App.Tab,
addTab: function(title, desc) {
this.pushObject(App.Tab.create({
title: title,
desc: desc
}));
},
init: function() {
this._super();
var i = 0;
for (i = 0; i <= 4; i++) {
this.addTab("hola" + i, "test " + i);
}
}
});
App.TabView = Ember.View.extend({
addTab: function() {
var title = get(this, 'title');
var desc = get(this, 'desc');
App.TabsController.addTab(title, desc);
}
});
App.initializeView = Ember.View.create({
templateName: 'mainview',
listBinding: 'App.TabsController',
clicked: function(view, event, context) {
console.log('clicked @', get(context, 'title'));
}
});
App.initializeView.appendTo('#container');
注意:在即将发布的版本中,action
回调的参数发生了变化,请参阅emberjs action event.target is undefined