search

Home  >  Q&A  >  body text

angular.js - How to match the data of two arrays in angularjs?

Now there are two arrays. The id value in array test1 corresponds to the value in test2. So now we want to implement, if the test1 id value = the id value in test2.idnum, put the id value in test2.idnum The number corresponding to the id value is output to the p tag. How do I do this matching and write the value into the p tag? Can this be done using filter?

html:

<p ng-repeat="td in test1">
<p id="{{td.id}}">
<p>该id对应的数值是:{{...}}<p>
</p>
</p>

First array

$scopt.test1=[{
"id": "x01",
"imgurl": "images/banner_01.jpg",
"status": "0"
},
{
"id": "x02",
"imgurl": "images/banner_01.jpg",
"status": "0"
},
{
"id": "x03",
"imgurl": "images/banner_01.jpg",
"status": "0"
}]

Second array

$scopt.test2=[{"dco":"xsadsq112341",
"reqs":"yes",
"idnum":{"x01":"1","x02":"3","x03":"0"}]
阿神阿神2865 days ago557

reply all(2)I'll reply

  • 世界只因有你

    世界只因有你2017-05-15 16:53:48

    html<p ng-repeat="td in test1">
    <p id="{{td.id}}">
    <p>该id对应的数值是:{{test2[0].idnum[td.id]}}<p>
    </p>
    </p>
    

    I wonder if this is the case?

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-15 16:53:48

    Filter can
    ng-if can also be used

    reply
    0
  • Cancelreply