我正在构建一个ember应用程序并想要创建一个选择菜单。选择菜单的其中一个选项必须是数据存储中的产品总数。
我已经为产品总数创建了一个属性。如何将其放入我创建选择菜单的数组中?代码如下:
HTML片段:
{{view "select" content=itemsPerPageOptions}}
控制器代码:
App.ProductsController = Ember.ArrayController.extend({
totalItems: function(){
return this.get('length');
}.property('length'),
itemsPerPageOptions : [1, 2, 3, 4, 5, this.totalItems],
});
目前,我在选择菜单中为最终选项获取了空白值。
答案 0 :(得分:0)
我认为您this.totalItems
itemsPerPageOptions
可用{}}
试试这个:
App.ProductsController = Ember.ArrayController.extend({
totalItems: function(){
return this.get('length');
}.property('length'),
itemsPerPageOptions: [],
init: function() {
var tmpOptions = [1, 2, 3, 4, 5];
var newVal = this.totalItems();
tmpOptions.push(newVal);
this.set(`itemsPerPageOptions`,tmpOptions);
}
});
我也不确定this.get('length')
是你在找什么,我不希望它返回任何价值。您可能正在寻找this.get('model.length')
。
答案 1 :(得分:0)
Make it a property depending on print("The length of '", word,"' is ", word_length, sep = '')
and use totalItems
because get('totalItems')
is also a property:
totalItems