Javascript 使用Angular.js和PHP时,筛选器功能未按预期工作
我有个问题。我需要使用Angular.js使用Javascript 使用Angular.js和PHP时,筛选器功能未按预期工作,javascript,php,angularjs,Javascript,Php,Angularjs,我有个问题。我需要使用Angular.js使用餐厅名称从表中筛选数据。我有一个搜索框。如果用户正在键入名称的第一个字母,则应过滤与该字母相关的所有名称。它不是那样发生的。我在下面解释我的代码 <div class="input-group" style="margin-bottom:10px; width:300px;"> <input class="form-control" placeholder="Type Restaurant Name" name="q" type="
餐厅名称
从表中筛选数据。我有一个搜索框。如果用户正在键入名称的第一个字母,则应过滤与该字母相关的所有名称。它不是那样发生的。我在下面解释我的代码
<div class="input-group" style="margin-bottom:10px; width:300px;">
<input class="form-control" placeholder="Type Restaurant Name" name="q" type="text" ng-model="searchProduct.rest_name">
</div>
<table class="table table-bordered table-striped table-hover" id="dataTable" >
<thead>
<tr>
<th>Sl. No</th>
<th>Restaurant Name</th>
</tr>
</thead>
<tbody id="detailsstockid">
<tr dir-paginate="cus in ($parent.labelResults=(listOfCustomerData | filter:searchProduct.rest_name:startsWith | orderBy:'rest_name')) | itemsPerPage:5 track by $index" current-page="currentPage">
<td>{{itemsPerPage *(currentPage-1)+$index+1}}</td>
<td>{{cus.rest_name}}</td>
</tr>
</tbody>
</table>
这里假设我有很多餐馆的名字,比如Anjum,A&p中国食品快车,Bookers BBQ&Crab Shack,Butcher And The Baker,Cactus Club Stephen Avenue,Cactus Club-Macleod Trail。在这里,当用户只在搜索框中键入一个时,名称以“应该”过滤器开头,但不是这样。如果我将静态值分配给对象$scope.listOfCustomerData
,则此功能按预期工作,但我使用PHP动态获取数据。但在我的情况下,情况并非如此。请帮帮我 试试这个-
在控制器中定义-
$scope.searchProduct=''代码>按照您的操作,它抛出了这个angularjs.js:107错误:[$parse:syntax]http://errors.angularjs.org/1.4.6/$parse/syntax?p0=%7C&p1=非%20a%20primary…表达式&p2=77&p3=(%24parent.labelResults%3D)(客户数据列表%20%20%7CNaNilter%3AstartsWith%3A'rest\u name'%3A%20%7C%orderBy%3A'rest\u name'))&p4=%7C%orderBy%3A'rest_name'))
错误。但如果我将静态数据分配给该$scope.listOfCustomerData
对象,我的代码也在工作,但我正在从数据库检索数据。所以它没有按照Expected运行。为什么要使用$parent.labelResults?我使用它在单击一个按钮后从表中获取所有过滤数据。这里我没有提到该按钮。请参阅编辑后的答案。如果对你有用的话。你不需要按任何按钮,它会自动过滤结果。
$http({
method:'GET',
url:"php/customerInfo.php?action=disp",
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
console.log('res',response.data);
$scope.listOfCustomerData=response.data;
},function errorCallback(response) {
})
$scope.startsWith = function (actual, expected) {
var lowerStr = (actual + "").toLowerCase();
return lowerStr.indexOf(expected.toLowerCase()) === 0;
}