我有兩個對象,我想組合在一個對象中,然後將它們放在一個數組中。我可以將一個對象和一個數組放在另一個數組中嗎?
vm.data = {};
vm.category_name_image = [] ;
getProductFunc=function(){
$http.get(ConfigCnst.apiUrl+'?route=categories').success(function (res) {
//console.log(res);
var sub_category = res;
console.log(sub_category);
var bagmankey = '-JweP7imFLfnh96iwn-c';
//console.log(bagmankey);
angular.forEach(sub_category, function (value, key) {
if (value.parentKey == bagmankey) {
// where i loop
vm.data.name = value.name;
vm.data.picture = value.image;
var selected = {
vm.data.name,
vm.data.picture
} // Where I group the two.
vm.category_name_image.push(seleted);
// where i want to place the both.
}
});
});
}
當我將vm.data.name和vm.data.picture放在所選對象中時,我似乎會收到錯誤。
我想我的輸出是這樣的:[{名稱,圖片},{名稱,圖片},{名稱,圖片}]
「_I似乎得到一個錯誤_」 你應該告訴我們是什麼錯誤。此外,這看起來像JavaScript,但被標記爲Java。你應該解決這個問題。 – csmckelvey
如何創建一個對象模型,然後創建一個基於模型的數組? –
@Takendarkk,我的控制器不確定... – Pickles