久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

javascript - angularjs怎么獲取repeat里的某些$index值?

瀏覽:146日期:2024-03-09 08:33:23

問題描述

<!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'}} /* 有時返回timeout */ //data = {status:'timeout',color:{color:'red'}} //push到arr數(shù)組,然后通過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的 } //我的需求就是當點擊 '獲取timeout的索引' 按鈕后 將這些timeout的狀態(tài)在重新請求,如果請求成功,就會把timeout顯示成on. //因為循環(huán)請求有時會timeout超時 //所以現(xiàn)在最大的問題就是怎么把 timeout重新請求.然后修改$rootScope.arr數(shù)組的相應下標位置,重點就在這里}); </script></body></html>

$rootScope.getOffIndex = function(){//這里如何獲取到全部的status:'timeout'的$index索引值.注意只要timeout的 }

我的需求就是當點擊 '獲取timeout的索引' 按鈕后 將這些timeout的狀態(tài)在重新請求,如果請求成功,就會把timeout顯示成on.因為循環(huán)請求有時會timeout超時所以現(xiàn)在最大的問題就是怎么把 timeout重新請求.然后修改$rootScope.arr數(shù)組的相應下標位置,重點就在這里

問題解答

回答1:

評論說遍歷arr是對的,

$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'}}];

你想象成,我獲得這個數(shù)組中,屬性為timeout的對象,他在這個數(shù)組中的index值

你可能是想在前臺直接判斷,可以做,不推薦這樣做

標簽: JavaScript
相關(guān)文章:
主站蜘蛛池模板: 周宁县| 平远县| 宜川县| 江城| 固镇县| 宁乡县| 崇阳县| 开化县| 姜堰市| 莫力| 台湾省| 江阴市| 红安县| 泾川县| 龙井市| 永宁县| 奉化市| 武胜县| 酒泉市| 探索| 锡林浩特市| 曲松县| 七台河市| 平乡县| 大厂| 望江县| 左贡县| 乐东| 南宫市| 布尔津县| 镇沅| 迭部县| 甘谷县| 马山县| 邹城市| 历史| 渝中区| 丽水市| 白河县| 宝丰县| 彩票|