使用 ng-repeat 的数组内数组
Array Within Array using ng-repeat
谁能帮我解析下面的内容 JSON 使用 ng-repeat 的请求
我想知道如何在 HTML 中使用 ng-repeat 来获取 问题的描述 在 JSON
使用下面的代码我得到了整个问题对象
posts.json
{
"persons": [
{
"properties": {
"label": "checked",
"type": "young"
},
"personType": "average",
"troubles": [],
"externalResourceLinks": []
},
{
"properties": {
"label": "checked",
"type": "aged"
},
"personType": "bad",
"troubles": [
{
"name": "Rocky",
"description": "Health problem",
"criticality": false,
"date": "2016-08-07T08:43:28+0000",
"longDate": 1470559408519
}
]
}
]
}
在 HTML 我正在使用
<tr>
<td class="features" ng-repeat="list in person">{{list.persontype}}</td>
</tr>
<tr>
<td class="features" ng-repeat="list in person">{{list.troubles}}</td>
</tr>
Angular 函数
var app = angular.module('myApp', ["ngTable"]);
app.controller('PostsCtrlAjax', ['$scope', '$http', function($scope, $http) {
$http({
method: 'POST',
url: 'scripts/posts.json'
}).success(function(data) {
$scope.post = data;
persons = data['persons'];
$scope.person = persons;
})
}
]);
你遇到了一系列麻烦,所以作为一个基于你的 JSON 的例子,这会起作用:
您的主要模块:
// app.js
(function() {
angular.module('myApp', ["ngTable"]);
})();
您的控制器:
// PostsCtrlAjax.js
(function() {
angular.module('myApp').controller('PostsCtrlAjax', PostsCtrlAjax);
PostsCtrlAjax.$inject = ['$scope', '$http'];
function PostsCtrlAjax($scope, $http) {
getPersons();
function getPersons() {
$http({
method: 'POST',
url: 'scripts/posts.json'
}).then(function(response) {
$scope.post = response.data;
}, function(errors) {
// any error handling goes here
});
}
}
})();
您的看法:
<!-- your other html here -->
<tr>
<td class="features" ng-repeat="person in post.persons">{{person.persontype}}</td>
</tr>
<tr>
<td class="features" ng-repeat="person in post.persons">
<p ng-repeat="trouble in person.troubles">{{trouble.description}}</p>
</td>
</tr>
<!-- the rest of your html here -->
希望您不介意我稍微整理一下您的代码,使其更加语义化。
谁能帮我解析下面的内容 JSON 使用 ng-repeat 的请求
我想知道如何在 HTML 中使用 ng-repeat 来获取 问题的描述 在 JSON
使用下面的代码我得到了整个问题对象
posts.json
{
"persons": [
{
"properties": {
"label": "checked",
"type": "young"
},
"personType": "average",
"troubles": [],
"externalResourceLinks": []
},
{
"properties": {
"label": "checked",
"type": "aged"
},
"personType": "bad",
"troubles": [
{
"name": "Rocky",
"description": "Health problem",
"criticality": false,
"date": "2016-08-07T08:43:28+0000",
"longDate": 1470559408519
}
]
}
]
}
在 HTML 我正在使用
<tr>
<td class="features" ng-repeat="list in person">{{list.persontype}}</td>
</tr>
<tr>
<td class="features" ng-repeat="list in person">{{list.troubles}}</td>
</tr>
Angular 函数
var app = angular.module('myApp', ["ngTable"]);
app.controller('PostsCtrlAjax', ['$scope', '$http', function($scope, $http) {
$http({
method: 'POST',
url: 'scripts/posts.json'
}).success(function(data) {
$scope.post = data;
persons = data['persons'];
$scope.person = persons;
})
}
]);
你遇到了一系列麻烦,所以作为一个基于你的 JSON 的例子,这会起作用:
您的主要模块:
// app.js
(function() {
angular.module('myApp', ["ngTable"]);
})();
您的控制器:
// PostsCtrlAjax.js
(function() {
angular.module('myApp').controller('PostsCtrlAjax', PostsCtrlAjax);
PostsCtrlAjax.$inject = ['$scope', '$http'];
function PostsCtrlAjax($scope, $http) {
getPersons();
function getPersons() {
$http({
method: 'POST',
url: 'scripts/posts.json'
}).then(function(response) {
$scope.post = response.data;
}, function(errors) {
// any error handling goes here
});
}
}
})();
您的看法:
<!-- your other html here -->
<tr>
<td class="features" ng-repeat="person in post.persons">{{person.persontype}}</td>
</tr>
<tr>
<td class="features" ng-repeat="person in post.persons">
<p ng-repeat="trouble in person.troubles">{{trouble.description}}</p>
</td>
</tr>
<!-- the rest of your html here -->
希望您不介意我稍微整理一下您的代码,使其更加语义化。