angularjs如何将两个数组的数据进行匹配?


如今有两个数组,数组test1里id的值和test2里的值是对应的,那么现在想要实现,如果test1 id值=test2.idnum里的id值的话,就把test2.idnum里的id值对应的数字输出到p标签里。请问这个要怎么做匹配并且把值写到p标签内?用filter可以做到吗?

html:


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

第一个数组


 $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"
}]

第二数组


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

angularjs 数组

雏月理理奈 9 years, 7 months ago

filter可以
ng-if也可以

两弹元老黄仁勋 answered 9 years, 7 months ago


 html


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

不知是否是要这样?

纯洁撸炮哥 answered 9 years, 7 months ago

Your Answer