我有一个Ember.js应用如下(借用this article上andyMatthews.net):Ember.js传递参数从视图控制器功能
检视:
<script type="text/x-handlebars" >
{{view App.UserTextField}}
{{#each App.recentUsersArray.reverse tagName="ul"}}
<li>{{this}}</li>
{{/each}}
</script>
应用程序:
App = Ember.Application.create();
App.UserTextField = Ember.TextField.extend({
insertNewline: function(){
var term = this.get('value');
App.recentUsersArray.pushObject(term);
}
});
App.recentUsersArray = Em.ArrayController.create({
content: ['noelle', 'evan', 'mason'],
reverse: function(){
return this.get('content').toArray().reverse();
}.property('[email protected]').cacheable(),
});
但我想从视图传递参数到App.recentUsersArray.reverse(例如,设置要返回的反转项目的数量)。我碰到一个问题,因为虽然你可以接受控制器功能上的参数,但它看起来并不像你可以从视图中传递它。我想象这样的事情,如果你想在参数3传递到反向功能的控制器上:
{{#each App.recentUsersArray.reverse(3) tagName="ul"}}
<li>{{this}}</li>
{{/each}}
但它抛出一个错误(未被捕获的错误:解析错误)...想法?最终目标是创建三个<ul>
,每个具有不同数量的元素而不是为每个长度创建不同的函数(即,App.recentUsersArray.reverseThree()
,App.recentUsersArray.reverseFive()
等)。我也不想制作三个不同的控制器,因为每个<ul>
都应该使用相同的数据源,只是切片不同。
你必须阅读有关性理解为什么之前如何计算工作你要求的是没有意义的。 –