【发布时间】:2019-09-18 16:43:48
【问题描述】:
我有一个从服务器接收到的对象产品数组。
return response()->json(['products' => $products->toArray()]);
这是它的日志:
而且我需要遍历它来获得product.attributes,我认为它是一个类似数组的对象,所以我使用Array.prototype.forEach.call
this.products.forEach(product => {
console.log(product);
console.log(product.attributes);
Array.prototype.forEach.call(product.attributes, function(child) {
// It seems the loop doesn't work, so nothing is printed out.
console.log(child);
});
});
但类似数组的对象上的循环似乎不起作用,因此没有打印任何内容,即使我的product.attributes 也不是空的。这是product.attributes日志:
【问题讨论】:
-
->表示法是什么?看起来不像 javascript? -
来自 Laravel
-
Object.keys [MDN, spec] — 一个函数,提供一个对象自身的名称数组,其名称是字符串的可枚举属性。 Object.values [MDN, spec] — 提供对象自身的可枚举属性值数组的函数。
标签: javascript vue.js