Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过单击另一个datatables AngularJS中的行来过滤一个表中的数据_Javascript_Angularjs_Datatable - Fatal编程技术网

Javascript 通过单击另一个datatables AngularJS中的行来过滤一个表中的数据

Javascript 通过单击另一个datatables AngularJS中的行来过滤一个表中的数据,javascript,angularjs,datatable,Javascript,Angularjs,Datatable,我显示了两个AngularJS数据表。第一个是县,第二个是镇。所以,我需要做的是通过单击第一个表中的一行来过滤第二个表中的数据。例如,当我在第一个表中单击Orange County所在的行时,第二个表中应该只过滤来自该县的城镇,而不是其他城镇。如果您有任何关于如何做到这一点的建议和建议,我们将不胜感激 这是我显示表格的代码: <div> <datatables-lazy columns="countiesColumns" options="countiesOpt

我显示了两个AngularJS数据表。第一个是县,第二个是镇。所以,我需要做的是通过单击第一个表中的一行来过滤第二个表中的数据。例如,当我在第一个表中单击Orange County所在的行时,第二个表中应该只过滤来自该县的城镇,而不是其他城镇。如果您有任何关于如何做到这一点的建议和建议,我们将不胜感激

这是我显示表格的代码:

<div>
        <datatables-lazy columns="countiesColumns" options="countiesOptions" class="grid"></datatables-lazy>
</div>
以下是从数据库获取数据的服务:

getCounties: function () {
        var deferred = $q.defer();
        $http.get(applicationSettings.humanResourcesAPIUrl + 'settings/getCountyList')
            .success(function (response) { deferred.resolve(response); })
            .error(function (err, status) { deferred.reject(err); });
        return deferred.promise;
    }, 
    getCounty: function (id) {

        var deferred = $q.defer();
        $http.get(applicationSettings.humanResourcesAPIUrl + 'settings/getCounty?countyId=' + id)
            .success(function (response) { deferred.resolve(response); })
            .error(function (err, status) { deferred.reject(err); });
        return deferred.promise;
    },

对于第二个数据表城镇,一切都是一样的。

您需要在第一个表上设置一个
ng单击
,以便它通过函数将所选城镇的值分配给变量

例如,
ng click=“setTown(town)”

$scope.activeTown=”“;
$scope.setTown=功能(城镇){
$scope.activeTown=town;
}
然后在第二个表中,您只需要对这个activeTown变量进行筛选

这里有一个例子

getCounties: function () {
        var deferred = $q.defer();
        $http.get(applicationSettings.humanResourcesAPIUrl + 'settings/getCountyList')
            .success(function (response) { deferred.resolve(response); })
            .error(function (err, status) { deferred.reject(err); });
        return deferred.promise;
    }, 
    getCounty: function (id) {

        var deferred = $q.defer();
        $http.get(applicationSettings.humanResourcesAPIUrl + 'settings/getCounty?countyId=' + id)
            .success(function (response) { deferred.resolve(response); })
            .error(function (err, status) { deferred.reject(err); });
        return deferred.promise;
    },