$scope.data=[
{"type":"00",
"obj":"[{"name":"a1","age":21},{"name" :"a2","age":21},{"name":"a3","age":21 }]"},
{"type":"01",
"obj":"[{"name":"a1","age":21},{"name":"a2" ,"age":21},{"name":"a3","age":21}]"}
]
Page template
<ul ng-repeat="item in data">
<li ng-repeat="detail in item.obj">{{detail.name}}{{detail.age}}</li>
</ul>
But because item.obj is not a array but a string object. My current method is just to control Loop the data array in the controller and convert the obj object into json. However, this method is not efficient because it requires looping to modify the data in the controller.
So I would like to ask if there is any way to change the item on the page. obj is converted into an array object, making ng-repeat effective, similar to
<li ng-repeat="detail in {{item.obj|Filter method}}">{{detail.name}}</li>Principal or other feasible methods,
过去多啦不再A梦2017-05-15 17:10:44
angular.module('app', [])
.filter('jsonParse', function() {
return function (str) {
try{
return JSON.parse(str);
}catch (e){
return str;
}
}
})
<ul ng-repeat="item in data">
<li ng-repeat="detail in item.obj | jsonParse">{{detail.name}}{{detail.age}}</li>
</ul>