angular.js - angularjs 用ng-reapt渲染的dom 怎么獲取上面的屬性
問題描述
angularjs 用ng-reapt渲染的dom 怎么獲取上面的屬性
問題解答
回答1:你屬性的數據本來就是循環出來的,直接去獲取數據就可以了,思路上永遠不要想jq的方法
repeat-finish=renderFinish(item)
$scope.renderFinish=function(item){ ... kit.log(item.id)}回答2:
謝邀,@crazy4x的方式也是OK的。data-* 的一般應用場景,沒使用MV*框架,使用事件代理的方式,避免列表數據變化時,需要手動添加/移除監聽。通過在父級添加監聽,然后獲取事件對象,然后獲取列表當前項的自定義屬性值,下面示例提供另外一種方式,僅供參考。
<!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是否執行完成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>
相關文章:
1. [python2]local variable referenced before assignment問題2. thinkPHP5中獲取數據庫數據后默認選中下拉框的值,傳遞到后臺消失不見。有圖有代碼,希望有人幫忙3. mysql主從 - 請教下mysql 主動-被動模式的雙主配置 和 主從配置在應用上有什么區別?4. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?5. linux運維 - python遠程控制windows如何實現6. python小白,關于函數問題7. django - Python error: [Errno 99] Cannot assign requested address8. python小白 關于類里面的方法獲取變量失敗的問題9. Python2中code.co_kwonlyargcount的等效寫法10. android - 請問一下 類似QQ音樂底部播放 在每個頁面都顯示 是怎么做的?
