您好,欢迎访问一九零五行业门户网

怎样监听angularJs列表数据是否渲染完毕

这次给大家带来怎样监听angularjs列表数据是否渲染完毕,监听angularjs列表数据是否渲染完毕注意事项有哪些,下面就是实战案例,一起来看一下。
前端在做数据渲染的时候经常会遇到在数据渲染完毕后执行某些操作,这几天就一直遇到在列表和表格渲染完毕后,执行点击和选择操作。对于angularjs处理这类问题,最好的方式就是指令 directive。
首先,定义指令:
app.directive('onfinishrenderfilters', function ($timeout) { return { restrict: 'a', link: function (scope, element, attr) { if (scope.$last === true) { //判断是否是最后一条数据 $timeout(function () { scope.$emit('ngrepeatfinished'); //向父级scope传送ngrepeatfinished命令 }); } } }; });
其次,指令定义完毕后,需要将指令添加到迭代的标签内,此处是<tr>标签
<div class="fixed-table-container" style="margin-right: 0px;"> <table class="table table-hover lamp-table"> <thead> <tr> <th></th> <th style="text-align: center; " data-field="name_device-id" tabindex="0" ng-repeat="i in provider.geozonelisthead track by $index" ng-hide=i.bol> <div class="th-inner sortable " style="padding-right: 10px">{{i.name}} </div> <div class="fht-cell" style="width: 101px;"></div> </th> </tr> </thead> <tbody> <tr ng-repeat="i in provider.geozonelist" onfinishrenderfilters> <td><input data-index="0" name="btselectitem" type="radio" value="{{$index}}" ng-click="selectinput($index)"></td> <td class="nameid0">{{$index+1}}</td> <td class="nameid1">{{i.geozonename}}</td> <td class="nameid2">{{i.description}}</td> <td class="nameid3">{{i.totalnumberofmembers}}</td> <td class="nameid4">{{i.country}}</td> <td class="nameid5">{{i.lastupdatedate}}</td> </tr> </tbody> </table> </div>
最后,在最后一条数据渲染完毕后,$emit用来向父级scope传送事件(命令),$brodercast是向子级scope传送事件(命令)。而$scope.$on()是监听事件,监听$emit或者$brodercast是否将事件(命令)传送回来,若事件已传送回来,则表示数据已经渲染完毕,就可以执行以后的其他操作了。
$scope.$on('ngrepeatfinished', function (ngrepeatfinishedevent) { var btnlist = $("input[name='btselectitem']"); btnlist.eq(0).attr("checked","checked"); $scope.provider.detaloutlet(); });
相信看了这些案例你已经掌握了方法,更多精彩请关注其它相关文章!
相关阅读:
详解浏览器渲染流程
html中关于盒模型的总结
以上就是怎样监听angularjs列表数据是否渲染完毕的详细内容。
其它类似信息

推荐信息