Javascript 使用搜索从JSON填充表
我完全能够从JSON对象实现网格-。但是,由于添加索引的性质,能够使用ng model和filter:search创建搜索栏不起作用-它只能搜索每个表行中的第一个 var测试=角度.moduleapp,[]; test.controllerappControl,函数$scope,$http{ $http。gethttp://www.w3schools.com/angular/customers.php .成功功能响应{ $scope.data=response.records; } ; $scope.getFiltered=functionobj,idx{ //设置要使用实际索引重复的项的属性 //仅对5项中的每1项返回true return!对象索引=idx%5; } }; {{work.Country} {{data[work.{u index+1].Country} {{data[work._index+2].Country} {{数据[work.{U index+3].国家} {{数据[工作.索引+4].国家}Javascript 使用搜索从JSON填充表,javascript,html,json,angularjs,angularjs-ng-repeat,Javascript,Html,Json,Angularjs,Angularjs Ng Repeat,我完全能够从JSON对象实现网格-。但是,由于添加索引的性质,能够使用ng model和filter:search创建搜索栏不起作用-它只能搜索每个表行中的第一个 var测试=角度.moduleapp,[]; test.controllerappControl,函数$scope,$http{ $http。gethttp://www.w3schools.com/angular/customers.php .成功功能响应{ $scope.data=response.records; } ; $sc
您可以尝试以下方法: var测试=角度.moduleapp,[]; test.controllerappControl,函数$scope,$http{ $http。gethttp://www.w3schools.com/angular/customers.php .成功功能响应{ $scope.data=response.records; $scope.filteredData=response.records; } ; $scope.$watch'search',函数{ var数组=[]; forvar i在$scope.data中 { 如果$scope.search==未定义的| |$scope.search.length==0 | |$scope.data[i].Country!=未定义的和$scope.data[i].Country.toUpperCase.startsWith$scope.search.toUpperCase{ array.push$scope.data[i]; } } $scope.filteredData=数组; }; $scope.getFiltered=functionobj,idx{ //设置要使用实际索引重复的项的属性 //仅对3项中的每1项返回true return!对象索引=idx%5; } }; {{work.Country} {{filteredata[work._index+1].Country} {{filteredata[work._index+2].Country} {{filteredata[work.\u index+3].国家} {{filteredata[work._index+4].Country}
您可以尝试以下方法: var测试=角度.moduleapp,[]; test.controllerappControl,函数$scope,$http{ $http。gethttp://www.w3schools.com/angular/customers.php .成功功能响应{ $scope.data=response.records; $scope.filteredData=response.records; } ; $scope.$watch'search',函数{ var数组=[]; forvar i在$scope.data中 { 如果$scope.search==未定义的| |$scope.search.length==0 | |$scope.data[i].Country!=未定义的和$scope.data[i].Country.toUpperCase.startsWith$scope.search.toUpperCase{ array.push$scope.data[i]; } } $scope.filteredData=数组; }; $scope.getFiltered=functionobj,idx{ //设置要使用实际索引重复的项的属性 //仅对3项中的每1项返回true return!对象索引=idx%5; } }; {{work.Country} {{filteredata[work._index+1].Country} {{filteredata[work._index+2].Country} {{filteredata[work.\u index+3].国家} {{filteredata[work._index+4].Country}
您可以在成功的Ajax调用之后以及每次模型搜索更改时对项目进行预筛选 将以前筛选的项目保存到$scope.workers中。 使用$scope.$watch监视模型搜索中的更改 使用函数searcheddata可使用indexOf方法筛选搜索字段中包含字符的条目。如果筛选器为空,还将显示$scope.search=='undefined'的每个项目类型。 如果希望搜索不区分大小写,请在使用.indexOf时将searchand和Country.toLowerCase转换为 然后您只需要一个角度过滤器$scope.getFiltered,它确保条目是五行的 var测试=角度.moduleapp,[]; test.controllerappControl,函数$scope,$http{ $http。gethttp://www.w3schools.com/angular/customers.php .成功功能响应{ $scope.data=response.records; $scope.workers=$scope.searched$scope.data; } ; $scope.getFiltered=functionobj,idx{ //设置要使用实际索引重复的项的属性 //仅对5项中的每1项返回true return!对象索引=idx%5; }; $scope.searched=函数数据{ var数组=[]; var max=0; 如果数据类型===“对象”{ max=数据长度; } 对于变量i=0;i