近日在完成angular的項目構建,當和easyui的datagrid結合時,我須要在datagrid的行選中onClickRow事件發生後獲取行的id時,並傳遞給angular的模型變量。以便個人angular刪除功能能夠使用, html
也許有人會問,爲何不用 app
<a ng-click="/xxxxx/"+row.id>刪除</a>通過個人測試,ng-click只會在dom生成時(編譯or鏈接時)進行賦值,運行期間沒法改變ng-click右邊的值(若是有不一樣的結果的朋友但願也能告訴我一聲),上easyui中datagrid的行點擊事件 代碼:
//當datagrid的onClickRow事件發生時,更改model中的id值 onClickRow : function(rowIndex, rowData) { //alert(rowData.id); //get a hold of controller and scope var element = angular.element($("#myDatagrid")); var controller = element.controller(); var scope = element.scope(); //as this happends outside of angular you probably have to notify angular of the change by wrapping your function call in $apply scope.$apply(function(){ scope.updateRowid(rowData.id); }); }
下面是我當前頁面的的angular控制器代碼, dom
app.controller('PermissionListCtrl', ['$scope', 'PermissionFactory','$routeParams', '$location', function($scope, PermissionFactory, $routeParams,$location) { $scope.rowid = ""; // 在permission列表頁面點擊編輯時,執行的function,即會跳轉到編輯頁面 $scope.editPermission = function(id) { $location.path('/permission/' + id); }; $scope.deletePermission = function (id) { PermissionFactory.delete({ id: $scope.rowid }); }; //datagrid的onclick事件會更新當前選中row的id,供刪除使用 $scope.updateRowid = function(id){ $scope.rowid = id; console.log(id); } }]);當我點擊datagrid中的某一行,我會在控制檯輸出當前行的id值,看一下是否能正常輸出:
顯示沒問題,同時點擊頁面上的刪除按鈕, ide
<a ng-click="deletePermission()">刪除</a>就能夠調用angular中的deletePermission() 的rest API完成刪除記錄的功能。