Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.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 使用搜索从JSON填充表_Javascript_Html_Json_Angularjs_Angularjs Ng Repeat - Fatal编程技术网

Javascript 使用搜索从JSON填充表

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

我完全能够从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].国家}
您可以尝试以下方法:

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您可以在成功的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问题是,我只希望搜索结果显示搜索结果,而不是整行更新我的答案。现在试试这个。如果有帮助,请告诉我。谢谢!我接受了它,只是做了一个小小的改动——我用includes替换了starts。这个答案仍然有一些缺陷,比如过滤器:搜索是不需要的。此外,检查未定义的变量不应针对UndefinedB而应针对“undefined”的类型进行,以此类推。看起来你只是抄袭了我的部分答案,却没有理解:他的答案实际上是第一个,对不起。另外,你的有一些问题,这一个没有-然而,我投了你的票,因为我只能接受一个答案。问题是,我只希望搜索结果显示搜索结果,而不是整行更新我的答案现在试试这个。如果有帮助,请告诉我。谢谢!我接受了它,只是做了一个小小的改动——我用includes替换了starts。这个答案仍然有一些缺陷,比如过滤器:搜索是不需要的。此外,检查未定义的变量不应针对UndefinedB而应针对“undefined”的类型进行,以此类推。看起来你只是抄袭了我的部分答案,却没有理解:他的答案实际上是第一个,对不起。此外,您的问题也有一些,但这一个没有-然而,我对您的问题投了反对票,因为我只能接受一个答案。是否可以不区分大小写搜索?我非常感谢您的回答和解释:是否可以不区分大小写搜索?我非常感谢您的回答和解释: