Ember.js 实现每个把手辅助对象的自定义余烬
我正在尝试针对以下情况实施helper:Ember.js 实现每个把手辅助对象的自定义余烬,ember.js,handlebars.js,Ember.js,Handlebars.js,我正在尝试针对以下情况实施helper: {{#inRange collection 1 3}} {{view App.SomeView content=this}} {{/inRange}} 所以,这个助手的目的是只呈现一些集合中的少数项->这是由第二个和第三个参数->开始和结束指定的 到目前为止,我正在尝试这样的方法: Ember.Handlebars.registerHelper('inRange', function (collection, start, end, optio
{{#inRange collection 1 3}}
{{view App.SomeView content=this}}
{{/inRange}}
所以,这个助手的目的是只呈现一些集合中的少数项->这是由第二个和第三个参数->开始和结束指定的
到目前为止,我正在尝试这样的方法:
Ember.Handlebars.registerHelper('inRange', function (collection, start, end, options) {
var res = '';
var data = Ember.Handlebars.get(this, collection);
data = data.slice(start, end);
data.forEach(function (item) {
res += options.fn(item);
});
return res;
});
options.hash.dataSourceBinding = path;
return Ember.Handlebars.helpers.collection.call(this, 'Ember.Handlebars.EachView', options);
但是如果我需要在块帮助器内部渲染视图
,这就不起作用了。我研究了native
Ember的每个实现,但他们正在以其他方式进行。
他们使用这样的东西:
Ember.Handlebars.registerHelper('inRange', function (collection, start, end, options) {
var res = '';
var data = Ember.Handlebars.get(this, collection);
data = data.slice(start, end);
data.forEach(function (item) {
res += options.fn(item);
});
return res;
});
options.hash.dataSourceBinding = path;
return Ember.Handlebars.helpers.collection.call(this, 'Ember.Handlebars.EachView', options);
这个问题是因为我找不到关于这些代码行的任何文档
是否有人知道我如何定制每个
助手,或者知道余烬每个
如何在内部工作?我想学习同样的内容。
但在您的情况下,与其创建自己的把手,不如创建一个子集合作为属性,并将其传递给每个
帮助器
视图类
subCollection: function(){
var collection = this.get('collection');
return collection.slice(1,3);
}.property()
{{#each subCollection}}
{{view App.SomeView content=this}}
{{/each}}
在车把中
subCollection: function(){
var collection = this.get('collection');
return collection.slice(1,3);
}.property()
{{#each subCollection}}
{{view App.SomeView content=this}}
{{/each}}
嗯,我知道这个解决方法,但我不喜欢它,因为在这种情况下,如果您可以提到helper,“视图类”中的代码是完全不必要的,并且如果您想创建多个“子集合”,视图/控制器中的代码将开始变脏。