angular.js - angularjs 用ng-reapt渲染的dom 怎么獲取上面的屬性
問題描述
angularjs 用ng-reapt渲染的dom 怎么獲取上面的屬性




問題解答
回答1:你屬性的數(shù)據(jù)本來就是循環(huán)出來的,直接去獲取數(shù)據(jù)就可以了,思路上永遠不要想jq的方法
repeat-finish=renderFinish(item)
$scope.renderFinish=function(item){ ... kit.log(item.id)}回答2:
謝邀,@crazy4x的方式也是OK的。data-* 的一般應用場景,沒使用MV*框架,使用事件代理的方式,避免列表數(shù)據(jù)變化時,需要手動添加/移除監(jiān)聽。通過在父級添加監(jiān)聽,然后獲取事件對象,然后獲取列表當前項的自定義屬性值,下面示例提供另外一種方式,僅供參考。
<!DOCTYPE html><html lang='en' ng-app='myapp'><head> <meta charset='UTF-8'> <title>Angular Repeat-Done Demo</title> <script src='https://cdn.bootcss.com/angular.js/1.6.3/angular.min.js'></script></head><body ng-app='myapp'><p ng-controller='AppCtrl'> <h4>Users List</h4> <ul><li ng-repeat='user in users' repeat-done='renderFinish($index)'> // user {{user.id}} - {{user.name}}</li> </ul></p><script type='text/javascript'> var myapp = angular.module('myapp', []) .directive(’repeatDone’, function () { // 用于判斷ng-repeat是否執(zhí)行完成return function (scope, element, attrs) { if (scope.$last) { // all are renderedattrs.repeatDone && scope.$eval(attrs.repeatDone); }} }) .controller('AppCtrl', [’$scope’, function ($scope) {$scope.users = [{ id: 1, name: ’Lolo’}, { id: 2, name: ’Semlinker’}];$scope.renderFinish = function(index) { // user對象 console.log(index);}; }])</script></body></html>
相關(guān)文章:
1. javascript - immutable配合react提升性能?2. javascript - sublime快鍵鍵問題3. 網(wǎng)頁爬蟲 - 如何使用使用java抓取信息并制作一個排名系統(tǒng)?4. javascript - 連續(xù)點擊觸發(fā)mouseleave事件5. python小白 自學看書遇到看不懂的地方6. DADB.class.php文件的代碼怎么寫7. php對mysql提取數(shù)據(jù)那種速度更快8. shell - mysql更新錯誤9. mysql - 在log日志中已知用戶的某一步操作,如何獲取其上一步操作?10. 如何設(shè)置一個無限循環(huán)并打破它。(Java線程)

網(wǎng)公網(wǎng)安備