2
私はAngularが新しく、文字を入力して検索して結果を返すときに検索を開始するフィルタリングメカニズムを作成しようとしています。
結果はDBから返されますが、問題が発生するのは、スコープ配列に結果を埋め込み、ng-repeatが起動しない場合です。
私のHTMLとJS:
app.controller("friendsController",function($scope,$http){
$scope.results =[];
$scope.onTextChange = function(){
var results = [];
var text = $scope.friendsLookupText;
$http({
url: 'utilities/getFriendsByValue.php',
method: 'POST',
data: {textValue: text}
}).success(function(data) {
if(data=="none")
{
$scope.results = results;
}
else
{
var stringResult = JSON.stringify(data);
var parsedResult = JSON.parse(stringResult);
$scope.results = parsedResult;
}
});
};
});
<div class="container-fluid" ng-controller="friendsController as friendsCtrl">
<input type="text" id="friendsLookupText" ng-model="friendsLookupText" ng-change="onTextChange()">
<ul class="list-group">
<div class="" ng-repeat="result in $scope.results">
<li class="list-group-item">{{result.username}}</li>
</div>
</ul>
</div>
誰が助けることができれば、私は喜んでいますよ。
を使用しています。ありがとう!あなたはちょうど私の日を作った。 – Shizzle
それを知ってよかった! –