Javascript 角度Js ng重复在div上显示错误的值

Javascript 角度Js ng重复在div上显示错误的值,javascript,html,css,angularjs,Javascript,Html,Css,Angularjs,我构建了一个Angular应用程序,并使用ng repeat在html视图中显示模型中的数据。但我得到了错误的价值观: 模型如下所示: [{ id : 1, name : 'jijo' address : 'addressone', }, { id : 2, name : 'albert' address : 'addressone', }, { id : 3, name : 'moana' address : 'addressone

我构建了一个Angular应用程序,并使用
ng repeat
在html视图中显示模型中的数据。但我得到了错误的价值观:

模型如下所示:

[{
   id : 1,
   name : 'jijo'
   address : 'addressone',
 },
 {
   id : 2,
   name : 'albert'
   address : 'addressone',
 },

{
   id : 3,
   name : 'moana'
   address : 'addressone',
 },
{
   id : 4,
   name : 'card'
   address : 'addressone',
 }
]
    <section id="main" ng-repeat="(id, name) in data.repo track by id"
    <div id="sub_main_one">
       {{id}} //prints one
     </div>

    <div id="sub_main_two">
       {{id}} //prints one
     </div>

     <div id="sub_main_three">
       {{id}} //prints one
     </div>

     <div id="sub_main_four">
       {{id}} //prints one
     </div>    


     <div id="sub_main_five">
       {{id}} //suppose to be one but prints 4 on the first repeat
     </div>

   </section> 
Html代码如下所示:

[{
   id : 1,
   name : 'jijo'
   address : 'addressone',
 },
 {
   id : 2,
   name : 'albert'
   address : 'addressone',
 },

{
   id : 3,
   name : 'moana'
   address : 'addressone',
 },
{
   id : 4,
   name : 'card'
   address : 'addressone',
 }
]
    <section id="main" ng-repeat="(id, name) in data.repo track by id"
    <div id="sub_main_one">
       {{id}} //prints one
     </div>

    <div id="sub_main_two">
       {{id}} //prints one
     </div>

     <div id="sub_main_three">
       {{id}} //prints one
     </div>

     <div id="sub_main_four">
       {{id}} //prints one
     </div>    


     <div id="sub_main_five">
       {{id}} //suppose to be one but prints 4 on the first repeat
     </div>

   </section> 

在您的代码中有很多缺少的
,那么您的
ng repeat
语句是错误的,obj
sintax中的
(键、值)是迭代对象的属性,而不是迭代数组中的项(查看文档):

确定:

<section id="main" ng-repeat="item in data">
  <div id="sub_main_one">
     {{item.id}}
     hey
   </div>
  <div id="sub_main_two">
     {{id}}
   </div>
   <div id="sub_main_three">
     {{id}}
   </div>
   <div id="sub_main_four">
     {{id}}
   </div>
   <div id="sub_main_five">
     {{id}}
   </div>
 </section> 

{{item.id}
嘿
{{id}
{{id}
{{id}
{{id}

这是一个

尝试将您的I的@JijoJohn@TheOneWhoMade你这是什么意思?@jijojojohn,你的分区标签写得好吗?
在你的开始标签中缺失了一个
,你的帖子中的I没有大写。英语专有名词。需要资本化。使它更容易阅读。让你更快地回答问题@JojoJohn \当您的模型显示1、2、3、4时,为什么它们都应该是1?而且,当你的评论说“第一次重复打印4”时,你的问题是“它给了我一个错误的值(9)”,好的,砰的一声!(OP首先应该做什么)顺便问一句,他甚至需要
的音轨吗?如果是这样,为什么不使用
按$index跟踪
?他不需要
跟踪,这只是为了处理重复的项目,请检查