我有这段代码:
let notificationList = angular.fromJson(response.data);
console.log(notificationList); /**FIRST PRINT**/
let numberOfMenuItems = notificationList.numberOfMenuItems;
console.log(" I have "+numberOfMenuItems+" Items"); /**SECOND PRINT**/
for(var i = 1; i <= numberOfMenuItems; i++){
console.log(notificationList); /**THIRD PRINT**/
let menuItemName = notificationList.('menuItemName'+i);
console.log(menuItemName);
let quantity = notificationList.('quantity'+i);
console.log(quantity);
}
但是当我运行我的代码时,FIRST PRINT会说我:
{
"numberOfMenuItems"="1",
"menuItemName1"="string1",
"quantity1"="2",
}
SECOND PRINT说我:
I have 1 Items
这是对的! 第三个打印我说:
notificationList [Object object]
然后menuItemName和数量未定义..我不会在循环之前更改notificationList的任何内容。但是当我输入时,notificationList似乎已更改,因为控制台说我与以前不同的东西.. 我做错了什么?我希望有一个人可以帮助我!提前谢谢
答案 0 :(得分:0)
这两行是错误的:
sp
将其替换为:
val[]
您的let menuItemName = notificationList.('menuItemName'+i);
let quantity = notificationList.('quantity'+i);
看起来如何?