AngularJs : วิธีแก้ไข Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: AngularJs : วิธีแก้ไข Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys

AngularJs : วิธีแก้ไข Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys

โดย thatsawan » 22/07/2016 12:32 am

Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: (key, value) in topicrow.TAGS, Duplicate key: string:กิจกรรม, Duplicate value: กิจกรรม

ปัญหาเกิดจาก ใน array ที่ส่งมา วน loop นั้นมีค่า value ซ้ำกัน

โค้ด: เลือกทั้งหมด

 <span class="badge_tag" ng-repeat="(key, value) in topicrow.TAGS ">
      <a class="text_tags" ng-click="search('{KEYWORD}', value)">[[value]]</a>
           </span>
วิธีแก้ไข ให้เพิ่มคำว่า track by $index ต่อท้าย

โค้ด: เลือกทั้งหมด

 <span class="badge_tag" ng-repeat="(key, value) in topicrow.TAGS track by $index">
       <a class="text_tags" ng-click="search('{KEYWORD}', value)">[[value]]</a>
      </span>

อ่านเพิ่มเติมที่ https://docs.angularjs.org/error/ngRepeat/dupes

ข้างบน