2017-07-12 8 views
1

表示しない:これは私がデータを取得する方法であるAngularJSのNG-繰り返し、私はこのJSON(エントリー)にリピートngをしたい任意の値

[{ 
    "Entry": { 
    "id": "1", 
    "title": "Test", 
    "person": "Test", 
    "description": "Test", 
    "created": "2017-07-11 20:19:55", 
    "modified": "2017-07-11 20:19:55", 
    "date_finished": "2017-07-11 20:19:00", 
    "finished": false 
    } 
}, { 
    "Entry": { 
    "id": "2", 
    "title": "Test 1", 
    "person": "Test 1", 
    "description": "Test 1", 
    "created": "2017-07-11 20:23:02", 
    "modified": "2017-07-11 20:23:02", 
    "date_finished": "2017-07-11 20:22:00", 
    "finished": false 
    } 
}, { 
    "Entry": { 
    "id": "3", 
    "title": "Test 2", 
    "person": "Test 2", 
    "description": "Test 2", 
    "created": "2017-07-11 20:23:13", 
    "modified": "2017-07-11 20:23:13", 
    "date_finished": "2017-07-11 20:23:00", 
    "finished": false 
    } 
}] 

を:

public function index() { 
    $this->Entry->recursive = 0; 
    $this->set('entries', $this->Paginator->paginate()); 
    $this->set('_serialize', 'entries'); 
} 

です私の表示コード:

<table class="table"> 
    <thead> 
    <tr> 
     <th>Title</th> 
     <th>Person</th> 
     <th>Description</th> 
     <th>Finished Date</th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr ng-repeat="entry in entries"> 
     <td>{{ entry.title }}</td> 
     <td>{{ entry.person }}</td> 
     <td>{{ entry.description }}</td> 
     <td>{{ entry.date_finished }}</td> 
    </tr> 
    </tbody> 
</table> 

しかし出力はありません。すべての値は空です。

json形式は大丈夫ですか?どんな提案も非常に役に立ちます。

答えて

4

アレイの各オブジェクトには、データを含むEntryオブジェクトが含まれています。

ですから、次のようにコードを変更することがあります。注意点として

<tr ng-repeat="entry in entries"> 
    <td>{{ entry.Entry.title }}</td> 
    <td>{{ entry.Entry.person }}</td> 
    <td>{{ entry.Entry.description }}</td> 
    <td>{{ entry.Entry.date_finished }}</td> 
</tr> 

を、あなたのJSONオブジェクトは、おそらくきれいな方法だろうリファクタリング、それは.Entryをコピーする必要がなくなります毎回。

0

entry.Entry.titleではなく、entry.titleである必要があります。他のキーを返さない場合は、Entryキーを削除できます。

-1

             
  
angular.module("myApp",[]) 
 
    .controller("myController", ['$scope', function($scope){ 
 
      $scope.entries = JSON.parse(JSON.stringify({ 
 
     "Entry": [{"Entry": { 
 
     "id": "1", 
 
     "title": "Test", 
 
     "person": "Test", 
 
     "description": "Test", 
 
     "created": "2017-07-11 20:19:55", 
 
     "modified": "2017-07-11 20:19:55", 
 
     "date_finished": "2017-07-11 20:19:00", 
 
     "finished": false 
 
     }},{ "Entry": { 
 
     "id": "2", 
 
     "title": "Test 1", 
 
     "person": "Test 1", 
 
     "description": "Test 1", 
 
     "created": "2017-07-11 20:23:02", 
 
     "modified": "2017-07-11 20:23:02", 
 
     "date_finished": "2017-07-11 20:22:00", 
 
     "finished": false 
 
     }},{"Entry": { 
 
     "id": "3", 
 
     "title": "Test 2", 
 
     "person": "Test 2", 
 
     "description": "Test 2", 
 
     "created": "2017-07-11 20:23:13", 
 
     "modified": "2017-07-11 20:23:13", 
 
     "date_finished": "2017-07-11 20:23:00", 
 
     "finished": false 
 
     }}] 
 
    })); 
 
    }])
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
    <html> 
 

 
     <body ng-app="myApp"> 
 
      <div ng-controller="myController"> 
 
       <table class="table"> 
 
     <thead> 
 
     <tr> 
 
      <th>Title</th> 
 
      <th>Person</th> 
 
      <th>Description</th> 
 
      <th>Finished Date</th> 
 
     </tr> 
 
     </thead> 
 
     <tbody> 
 
     <tr ng-repeat="entry in entries.Entry"> 
 
      <td>{{entry.Entry.title}}</td> 
 
      <td>{{entry.Entry.person}}</td> 
 
      <td>{{entry.Entry.description}}</td> 
 
      <td>{{entry.Entry.date_finished}}</td> 
 
     </tr> 
 
     </tbody> 
 
    </table> 
 
      </div> 
 
     </body> 
 
    </html>
+0

コード専用の回答は避けてください。代わりに、あなたのコードが何をしているのか、それがどのようにして問題を解決するのかを説明してください。 – Mistalis