2021年编辑:
免责声明,这个问题是在我刚接触HTML和JS时写的。如果你想在这里寻找问题的帮助,这可能没有帮助因为我的代码非常混乱。对给你带来的不便深表歉意。这个问题将根据网站指南保留。
原始帖子
我正在尝试使用angularJS创建一个表,它从js汽车列表中提取信息,并将其显示在一个表中。根据规范,这必须使用Angular来完成,尽管存在更简单的方法。
我目前的问题是,不是输出信息,而是每列显示格式化代码(例如,{{ car.Model }}
)。
我目前的代码如下:
第一个
cars.js如下:
var cars = [
{"manufacturer":"Toyota",
"model":"Rav4",
"year":2008,
"stock":3,
"price":8500},
{"manufacturer":"Toyota",
"model":"Camry",
"year":2009,
"stock":2,
"price":6500},
{"manufacturer":"Toyota",
"model":"Tacoma",
"year":2016,
"stock":1,
"price":22000},
{"manufacturer":"BMW",
"model":"i3",
"year":2012,
"stock":5,
"price":12000},
{"manufacturer":"Chevy",
"model":"Malibu",
"year":2015,
"stock":2,
"price":10000},
{"manufacturer":"Honda",
"model":"Accord",
"year":2013,
"stock":1,
"price":9000},
{"manufacturer":"Hyundai",
"model":"Elantra",
"year":2013,
"stock":2,
"price":7000},
{"manufacturer":"Chevy",
"model":"Cruze",
"year":2012,
"stock":2,
"price":5500},
{"manufacturer":"Dodge",
"model":"Charger",
"year":2013,
"stock":2,
"price":16000},
{"manufacturer":"Ford",
"model":"Mustang",
"year":2009,
"stock":1,
"price":8000},
]
1条答案
按热度按时间polhcujo1#
您正在迭代“roll in汽车”,但在打印它时使用了“car”。将其替换为(ng-repeat =“roll in cars”to ng-repeat =“car in cars”)。在原始var cars集合中,您使用了属性的小写名称,而在将其分配给$scope.cars时,您使用了大写的属性首字母(例如“Manufacturer:汽车[0].制造商”应为“制造商:汽车[0].manufacturer”)。此外,我还重构了您的代码,以便在循环中迭代cars并将其推送到$scope.cars。
第一个