我的页面上有一个文本框,用户输入他们想要搜索的用户名,然后单击提交按钮.我想要实现的是当用户点击提交按钮时,结果应立即推送到页面.
使用我的脚本它所做的只显示一个结果,即使可能有10个或更多
使用我的脚本它所做的只显示一个结果,即使可能有10个或更多
JS
.controller('search_ctrl',['$scope','$http','$location','$ionicLoading','$ionicPopup','$state','$stateParams','$cordovaToast',function($scope,$http,$location,$ionicLoading,$ionicPopup,$state,$stateParams,$cordovaToast){ $scope.username=localStorage.getItem("username"); $scope.searchresults = []; $scope.expendsearch=function() { $ionicLoading.show({template: '<p>Please Wait...</p><ion-spinner></ion-spinner>'}); event.preventDefault(); $http.post("http://localhost/app/templates/spree/sales/expenses/search_results.PHP",{'username':$scope.username}) .success(function(data){ //console.log(JSON.stringify(data)); $scope.results=data; {$ionicLoading.hide();} var search ={"fullname":data[0].reciever,"username":data[0].amount}; $scope.searchresults.push(search); }).error(function(error){ console.error(error); }); } }])
HTML
<div ng-controller="search_ctrl" ng-repeat="item in searchresults track by $index"> {{item.username}} {{item.fullname}} </div>
当我将我的脚本更改为:
.controller('search_ctrl',$cordovaToast){ $scope.username=localStorage.getItem("username"); $scope.searchresults = []; $scope.expendsearch=function() { $ionicLoading.show({template: '<p>Please Wait...</p><ion-spinner></ion-spinner>'}); event.preventDefault(); $http.post("http://localhost/app/templates/spree/sales/expenses/search_results.PHP",{'username':$scope.username}) .success(function(data){ //console.log(JSON.stringify(data)); $scope.results=data; {$ionicLoading.hide();} var search ={"fullname":data.reciever,"username":data.amount}; $scope.searchresults.push(search); }).error(function(error){ console.error(error); }); } }])
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。