我不知道这是否是一个常见的问题,但是使用Magento 2,当属性名为length时,它会给出以下错误:
RangeError:无效数组长度
var self = this;
if (self.attributeNames == null) {
self.attributeNames = [];
self.attributeNames['category_names'] = 'Category';
$.each(this.availableFilters, function(index, item){
self.attributeNames[item.attribute_code] = item.frontend_label;
});
}
return self.attributeNames;这里,item.attribute_code是动态的,它来自Magento属性。因此,当我以length的形式创建属性时,我的代码是:
self.attributeNames[length] = Length;这给我留下了上面的错误,当我使用它。
我怎样才能克服这一切?
发布于 2017-09-18 14:41:01
在第三行中,您应该分配一个空对象(而不是空数组),即self.attributeNames = {}。使用数组,您可以使用push方法添加新项,并仅将值赋值给现有项(按数字索引)。对于对象,可以在运行时添加任何特定字段,就像在第四行中那样。
https://stackoverflow.com/questions/46280798
复制相似问题