2016-12-29 62 views
0

我有與物體array.It在角控制器中的範圍可變呼叫項目是按以下格式,這是它的表示鉻控制檯的方式,Angularjs納克重複值打印問題

data 
Array[4] 
0 
: 
Object 
created_at 
: 
"2016-12-29 08:20:21" 
id 
: 
1 
name 
: 
"Developer questions" 
question_classification_type_id 
: 
1 
status 
: 
1 
updated_at 
: 
"2016-12-29 08:20:21" 

所以這是我在html中的ng-repeat指令。

<span ng-repeat="result in items track by $index"> 
<p>{{result.name}}</p> 
<p>{{result.description}}</p> 
</span> 

但它沒有顯示在view.I什麼都可以搞不清楚的原因,因爲我以前做過類似的東西,沒有任何issues.So請幫助別人解決這個問題。

+0

你有什麼錯誤? – Garfield

+0

我的控制檯中沒有出現任何與此相關的錯誤。 – CodeCanyon

+0

我試過了,但仍未顯示。 – CodeCanyon

回答

0

result.description在您提供的items數組中沒有任何描述,如果您不會發布一些控制器代碼,我們會給出自己的例子,並與此進行比較,並嘗試確定您的missing.My建議是爲了控制從指定服務或API,並與我公司提供的格式....有時五月的樣子res.data或data.data檢查數據後$ scope.items .....

var app = angular.module('plunker', []); 
 

 
app.controller('MainCtrl', function($scope) { 
 
    $scope.items = [ 
 
    { 
 
     "created_at":"2016-12-29 08:20:21", 
 
     "id":1, 
 
     "name":"Developer questions", 
 
     "question_classification_type_id":1, 
 
     "status":1, 
 
     "updated_at":"2016-12-29 08:20:21" 
 
     
 
    }, 
 
{ 
 
     "created_at":"2016-12-30 08:20:21", 
 
     "id":2, 
 
     "name":"Developer answers", 
 
     "question_classification_type_id":1, 
 
     "status":1, 
 
     "updated_at":"2016-12-30 08:20:21" 
 
     
 
    }, 
 
] 
 
});
<!DOCTYPE html> 
 
<html ng-app="plunker"> 
 

 
    <head> 
 
    <meta charset="utf-8" /> 
 
    <title>AngularJS Plunker</title> 
 
    <script>document.write('<base href="' + document.location + '" />');</script> 
 
    <link rel="stylesheet" href="style.css" /> 
 
    <script data-require="[email protected]" src="https://code.angularjs.org/1.4.12/angular.js" data-semver="1.4.9"></script> 
 
    <script src="app.js"></script> 
 
    </head> 
 

 
    <body ng-controller="MainCtrl"> 
 
    <pre>{{items}}</pre> 
 
<span ng-repeat="result in items track by $index"> 
 
<p>{{result.name}}</p> 
 
<p>{{result.description}}</p> 
 
</span> 
 
    </body> 
 

 
</html>

+0

感謝您的代碼。但我認爲我的陣列有點不同。它有一個數組索引號以及之前的對象,如0,1,2,... – CodeCanyon