Javascript 如何获取角度数据表中的双击事件
我使用的是数据表和角度数据表。 如何在datatable中检测双击事件并获取行数据? 我找到了下面的代码,但我需要它的角度Javascript 如何获取角度数据表中的双击事件,javascript,angularjs,angular-datatables,Javascript,Angularjs,Angular Datatables,我使用的是数据表和角度数据表。 如何在datatable中检测双击事件并获取行数据? 我找到了下面的代码,但我需要它的角度 $(document).on("dblclick", "#myTable tr", function () { //code here }); html <table datatable="tblRecipe" dt-options="showCase.dtOptions" dt-columns="showCase.dtColumns" dt-instanc
$(document).on("dblclick", "#myTable tr", function () {
//code here
});
html
<table datatable="tblRecipe" dt-options="showCase.dtOptions" dt-columns="showCase.dtColumns" dt-instance="showCase.dtInstance" class="table table-bordered"></table>
controller.js
var app = angular.module('app', ['datatables'])
app.controller('MainController', function ($scope, $window, $http, $filter, $timeout, $compile, DTOptionsBuilder, DTColumnDefBuilder, DTColumnBuilder) {
var vm = this;
vm.dtInstance = {};
vm.Recipes = {};
vm.delete = deleteRow;
vm.edit = editRow;
vm.dtOptions = DTOptionsBuilder.newOptions()
.withOption('ajax', {
url: "/Recipes/GetAllRecipes",
type: "POST"
})
.withOption('createdRow', createdRow)
.withOption('select', true);
vm.dtColumns = [
//...
DTColumnBuilder.newColumn(null).withTitle('Actions').notSortable().renderWith(actionsHtml)
];
function actionsHtml(data, type, full, meta) {
vm.Recipes[data.Id] = data;
return '<a title="View" href="javascript:void(0)" ng-click="showCase.view(showCase.Recipes[' + data.Id + '])">' +
' <i class="fa fa-eye" aria-hidden="true"></i>' + '</a>' + '<a title="Edit" href="javascript:void(0)" ng-click="showCase.edit(showCase.Recipes[' + data.Id + '])">' +
' <i class="fa fa-pencil"></i>' + '</a>' + '<a title="Delete" href="javascript:void(0)" ng-click="showCase.delete(showCase.Recipes[' + data.Id + '])" )"="">' + ' <i class="fa fa-trash-o"></i>' + '</a>';
};
//...
});
});
var-app=angular.module('app',['datatables'))
app.controller('MainController',函数($scope、$window、$http、$filter、$timeout、$compile、DTOptionsBuilder、DTColumnDefBuilder、DTColumnBuilder){
var vm=这个;
vm.dtInstance={};
vm.Recipes={};
vm.delete=deleteRow;
vm.edit=editRow;
vm.dtOptions=DTOptionsBuilder.newOptions()
.withOption('ajax'{
url:“/Recipes/GetAllRecipes”,
类型:“职位”
})
.withOption('createdRow',createdRow)
.withOption('select',true);
vm.dtColumns=[
//...
DTColumnBuilder.newColumn(null).withTitle('Actions').notSortable().renderWith(actionsHtml)
];
函数actionsHtml(数据、类型、完整、元){
vm.Recipes[data.Id]=数据;
返回“”+“”+“”;
};
//...
});
});
我们可以编写自定义指令逻辑并解决问题。请你参考一下
html代码
<div ng-controller="MainController">
<div id="goodDiv" ngdblclick>Click Here</div>
<div id="goodDiv">Don't Click Here</div>
</div>
css样式:
#goodDiv{
width : 100px;
height : 100px;
background-color : green;
}
您可以找到您的元素并呈现特定元素的事件(#myTable li)
我使用的是数据表和角度数据表。我怎样才能检测到双重身份
单击datatable中的事件并获取行数据?我找到密码了
下面,但我需要它的角度
$(document).on("dblclick", "#myTable tr", function () {
//code here
});
DataTables是jQuery,AngularDataTables只是使它们在AngularJS上下文中工作的指令。除非呈现“角度方式”,即datatable=“ng”
,否则如果希望任何指令起作用,您需要$compile
回调中的表、行或每个单元格
只需像处理jQuery DataTables一样使用委托事件处理程序,并通过dtInstance
获取数据,其中包含API实例:
$('#tableId').on('dblclick', 'tbody tr', function() {
console.log( $scope.dtInstance.DataTable.row(this).data() )
})
更新:你在使用angularjs 1吗?@Sathiyaraj是的,angularjs 1.6.6你能发布代码吗?@Sajeetharan我没有双击事件的角度代码,这就是我要问的。我将编辑我的问题标题。1,为什么要在指令中插入
$compile
?2.为什么要使用setTimeout
?3.为什么不使用angularjs自己的ng dblclick
$compile是动态的,它重新绑定元素并获取值的范围,2。我们需要了解下一个连续单击事件的间隔时间listen 3。无法在angular元素注入中绑定ng双击事件。1。您根本没有使用$compile
,$compile
在指令方法中是隐式的。2.您不应该对angularjs使用setTimeout
,而应该使用$timeout
3。您的解决方案永远不会使用angular数据表,因为angular不知道DT正在注入什么DOM元素。您只需将一个没有$compile
就无法工作的标准指令替换为另一个没有$compile
就无法工作的指令。。。