ng-repeat 在离子 1 中显示错误值

ng-repeat showing wrong values in ionic 1

<ion-item
  class="item-icon-left item-icon-right item-avatar"
  ng-repeat="note in taskDetails.notes track by note.note_id"
  ng-click="viewNote(note)">
  <i ng-show="note.status.name==Open" class="icon ion-ios-circle-outline"></i>
  <i ng-show="note.status.name!=Open"class="icon ion-ios-checkmark-outline"></i>
  <h2>{{note.note}}</h2>
  <p>{{note.created_by}}</p>
  <i class="icon ion-chevron-right icon-accessory"></i>
</ion-item>

Task Object

{"task_date_id":69069,"task_id":"3286","start_time":"2018-02-22 12:10:00","end_time":"2018-02-22 12:10:00","overdue_days":0,"subject":"Oneone","description":"One","status":{"id":3,"name":"Pending","enabled":null,"complete":null},"statuses":[{"id":3,"name":"Pending"},{"id":6,"name":"Assigned"},{"id":4,"name":"Closed"},{"id":17,"name":"Complete"}],"type":{"id":229,"name":"200_Test_Mobile_Task"},"assigned_to":"Kanishka Raveendra","address":"","clients":[],"attachments":[],"notes":[],"$$hashKey":"object:8112"}

Note Object

{"note_id":"98834","note_date":"22/02/2018","note_type":"ABC14","time_spent":0,"note":"Xyxhxffuf\n

{$PERSON_FIRST_NAME} {$PERSON_SURNAME}

","created_by":"Kanishka Raveendra","date_created":"","attachments":[],"template":"

{$PERSON_FIRST_NAME} {$PERSON_SURNAME}

","type":{"id":52,"name":"ABC14","enabled":true,"record_time":"start_stop"}}

这里我添加了 Task 和 Note 的源代码和响应,我用来显示 data.Normally 一个任务可以有多个 notes.But 这里很明显我们可以看到 notes 数组没有 elements.But 我可以在 View.I 中看到其他任务的一些注释对象需要在 View.please 帮助中显示正确的注释值 me.I 我是 ionic 的新手。

Console error

Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: note in taskDetails.notes track by note.note_id, Duplicate key: 98834, Duplicate value: {"note_id":"98834","note_date":"22/02/2018","note_type":"ABC14","time_spent":0,"note":"Xyxhxffuf\n

{$PERSON_FIRST_NAME} {$PERSON_SURNAME}

","created_by":"Kanishka Raveendra","date_created":"","attachments":[],"template":"

{$PERSON_FIRST_NAME} {$PERSON_SURNAME}

","type":{"id":52,"name":"ABC14","enabled":true,"record_time":"start_stop"}}

在你的 track by note.note_id 中得到相同的值。

使用 $index 这是 ng-repeat.

中重复元素 (0..length-1) 的迭代器偏移量

请查看 here 的详细信息。

使用以下解决方案:

      <ion-item
        class="item-icon-left item-icon-right item-avatar"
        ng-repeat="note in taskDetails.notes track by $index"
        ng-click="viewNote(note)">
        <i class="icon" ng-class="{'ion-ios-circle-outline': note.status.name === 'Open', 'ion-ios-checkmark-outline': note.status.name !== 'Open'}"></i>

        <h2>{{note.note}}</h2>
        <p>{{note.created_by}}</p>
        <i class="icon ion-chevron-right icon-accessory"></i>
      </ion-item>

希望对您有所帮助!!

试试这个

<ion-item
        class="item-icon-left item-icon-right item-avatar"
        ng-repeat="(key, value) in taskDetails.notes track by $index"
        ng-click="viewNote(note)">
        ......
</ion-item>