我有一个json如下.
{
"id":14,"discussion":8,"parent":0,"userid":2,"subject":"communication skill discussion 2","message":"
我想首先获取其ID与子数组中的元素匹配的详细信息
例如对于id:14有3个孩子24,15.然后控件应该直接转到id:15并获取id的详细信息:15.Again id有孩子,例如.考虑id:23,没有孩子,将直接打印消息.
请指导我如何使用角度的ng-repeat实现此目的?
最佳答案
请参阅demo.
请找到以下代码:
HTML:
JS:
var app = angular.module('app',[]);
app.controller('test',function($scope) {
$scope.data = [{
"id": 14,"discussion": 8,"parent": 0,"userid": 2,"subject": "communication skill discussion 2","message": "
UPDATE: As per the request
HTML:
JS:
$scope.getMessage = function(itemId) {
var flag = true;
var msg;
angular.forEach($scope.data,function(value,key) {
if (flag && value.id == itemId) {
flag = false;
msg = value.message;
}
});
return $sce.trustAsHtml(msg);
}
CSS:
.green {
color: green;
}