javascript - angularjs怎么獲取repeat里的某些$index值?
問(wèn)題描述
<!DOCTYPE html><html ng-app='app'><head> <title></title> <script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js'></script></head><body> <ul><li ng-repeat='d in arr' > <span ng-bind='$index'></span> <span ng-bind='d.status' ng-style='d.color'></span></li> </ul> <a href='javascript:void(0)' ng-click='getOffIndex()'>獲取timeout的索引</a> <script type='text/javascript'>var app = angular.module('app',[]);app.run(function($rootScope){ for(var i=0; i<10; i++){$http({ method : 'JSON', url : '/xxxx/data'}).then(function(data){ /* data返回的數(shù)據(jù) */ //data = {status:'on',color:{color:'#000'}} /* 有時(shí)返回timeout */ //data = {status:'timeout',color:{color:'red'}} //push到arr數(shù)組,然后通過(guò)repeat循環(huán)展示 /*$rootScope.arr = [{status:'on',color:{color:'#000'}},{status:'on',color:{color:'#000'}},{status:'timeout',color:{color:'red'}},{status:'on',color:{color:'#000'}},{status:'timeout',color:{color:'red'}},{status:'on',color:{color:'#000'}},{status:'on',color:{color:'#000'}},{status:'on',color:{color:'#000'}},{status:'on',color:{color:'#000'}},{status:'on',color:{color:'#000'}},{status:'timeout',color:{color:'red'}} ];*/ $rootScope.arr.push(data);},function(){}); } $rootScope.getOffIndex = function(){//這里如何獲取到全部的status:'timeout'的$index索引值.注意只要timeout的 } //我的需求就是當(dāng)點(diǎn)擊 '獲取timeout的索引' 按鈕后 將這些timeout的狀態(tài)在重新請(qǐng)求,如果請(qǐng)求成功,就會(huì)把timeout顯示成on. //因?yàn)檠h(huán)請(qǐng)求有時(shí)會(huì)timeout超時(shí) //所以現(xiàn)在最大的問(wèn)題就是怎么把 timeout重新請(qǐng)求.然后修改$rootScope.arr數(shù)組的相應(yīng)下標(biāo)位置,重點(diǎn)就在這里}); </script></body></html>
$rootScope.getOffIndex = function(){//這里如何獲取到全部的status:'timeout'的$index索引值.注意只要timeout的 }
我的需求就是當(dāng)點(diǎn)擊 '獲取timeout的索引' 按鈕后 將這些timeout的狀態(tài)在重新請(qǐng)求,如果請(qǐng)求成功,就會(huì)把timeout顯示成on.因?yàn)檠h(huán)請(qǐng)求有時(shí)會(huì)timeout超時(shí)所以現(xiàn)在最大的問(wèn)題就是怎么把 timeout重新請(qǐng)求.然后修改$rootScope.arr數(shù)組的相應(yīng)下標(biāo)位置,重點(diǎn)就在這里
問(wèn)題解答
回答1:評(píng)論說(shuō)遍歷arr是對(duì)的,
$rootScope.arr = [ {status:'on',color:{color:'#000'}}, {status:'on',color:{color:'#000'}}, {status:'timeout',color:{color:'red'}}, {status:'on',color:{color:'#000'}}, {status:'timeout',color:{color:'red'}}, {status:'on',color:{color:'#000'}}, {status:'on',color:{color:'#000'}}, {status:'on',color:{color:'#000'}}, {status:'on',color:{color:'#000'}}, {status:'on',color:{color:'#000'}}, {status:'timeout',color:{color:'red'}}];
你想象成,我獲得這個(gè)數(shù)組中,屬性為timeout的對(duì)象,他在這個(gè)數(shù)組中的index值
你可能是想在前臺(tái)直接判斷,可以做,不推薦這樣做
相關(guān)文章:
1. 我在centos容器里安裝docker,也就是在容器里安裝容器,報(bào)錯(cuò)了?2. CSS3可否做出這個(gè)效果?3. 如何編寫可以用Java計(jì)算能力的函數(shù)。無(wú)循環(huán)4. 基于Nginx的Wordpress安裝失敗?5. javascript - vue中怎么給input的value綁定計(jì)算屬性6. wordpress - nginx 反代 Varnish 走 Https ,WP后臺(tái) ‘您沒(méi)有足夠的權(quán)限訪問(wèn)該頁(yè)面。’7. javascript - ui-router可否控制歷史記錄8. mongoDB批量插入文檔時(shí),運(yùn)行下面代碼,用MongoVUE查看數(shù)據(jù)庫(kù),mongo庫(kù)中只存在一個(gè)文檔?不應(yīng)該是20個(gè)嗎?9. Java OutputStream等效于getClass()。getClassLoader()。getResourceAsStream()10. type=text/css是什么意思
