【发布时间】:2017-09-06 03:32:55
【问题描述】:
我有来自数组列表的对象数组。我使用 JSON.parse 对象的方法将对象字符串转换为对象,但它在 ng-repeat 中显示为空。
翡翠
.item.col-md-4(ng-repeat='p in searchData | filter: paginate | orderBy: sortKey ')
// `p` is a object of string, for example "{id:2, name:'abel'}";
- var property = JSON.parse("{{ p }}"); // Error at this line
+AddPropertyCard(property)
搜索数据
[{id:0, name:"abel"},{id:1, name:"julia"}]
错误
var 属性 = JSON.parse("");
位置 1 的 JSON 中的意外令牌 {
【问题讨论】:
-
你能告诉我们你的 JSON 吗?
-
p好像是空的,先检查p的值。 -
@leaf {{ p }} 返回对象。
-
这不起作用,jade 试图解析服务器上的属性,而不是客户端,但 ng-repeat 没有在服务器上展开。除此之外,无论如何您都不需要需要
JSON.parse; ng-repaeat 应该已经有单独的p对象,{{p.id}}和{{p.name}}应该直接输出。 -
很可能,您只需要
+AddPropertyCard(p),JSON.parse的行就可以完全消失。
标签: javascript angularjs json pug