angular(1.x)两个数组作对比

scopea=[11,33,55,77];另一数组b是a的子集,scope b = [33,55]
a数组会用<input type="checkout"/>标签在html页面中循环渲染出来,并勾选数组b的值
请问如何实现?谢谢

qq_笑_17
浏览 504回答 1
1回答

潇湘沐

js:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $scope.a=[1,2,3,4];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $scope.b=[3];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $scope.fn=function(val) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return $scope.b.indexOf(val)!=-1?true:false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };html:&nbsp; &nbsp; &nbsp; &nbsp; <div ng-repeat="(key, value) in a">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="checkbox" ng-value="value" ng-checked="fn(value)">{{value}}&nbsp; &nbsp; &nbsp; &nbsp; </div>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript