2017-11-29 6 views
0

私はこのようなカスタムのディレクティブがあります。 ng-repeatの使用中に古いデータを削除して新しいデータをテーブルにバインドするにはどうすればよいですか?

<table id="usertbl" class="table table-hover table-bordered" style=" 
position: relative; 
    top: 27px; 
"> 
    <tr> 
     <th>Firstname</th> 
     <th>Lastname</th> 
     <th>gender</th> 
     <th>state</th> 
     <th>zip</th> 
     <th>email</th> 
     <th>mobile</th> 
     <th>Delete</th> 
     </tr> 

    <tr ng-repeat="x in users"> 
    <td>{{ x.fName }}</td> 
    <td>{{ x.lName }}</td> 
    <td>{{ x.gender }}</td> 
    <td>{{ x.state }}</td> 
    <td>{{ x.zip }}</td> 
    <td>{{ x.email }}</td> 
    <td>{{ x.mobile }}</td> 
    <td><button class="btn btn-danger" ng-click="clickFunc(x.email)">Delete Customer</button></td> 
    </tr> 

</table> 

</body> 


http.get("getallusers.do",{ params:{pageno:count,pageSize:2}}).then(function(response) { 
        //First function handles success 
        scope.users = response.data;)} 

ワンボタンの横には、それはデシベルから10件のレコードをフェッチしますクリックするたびがありますが、それぞれの時間は、10レコードがで既存の10レコードに追加されますUIテーブル。私は新しい10レコードだけをテーブルに追加したい。

+1

$scope.$apply()を呼び出す必要があります。 'scope.users'は配列ではないので、** API' **呼び出しを行っている間は常に新しいレコードセットを持ちます。 ** 'Next' **ボタンをクリックすると、常に新しいレコードセットが表示されます。 –

答えて

0

クリアアレイと、あなたは、これは、あなたが新しいデータを

最初の配列をクリアしてからプッシュすることができます行うための方法を持っている

scope.users =[]; 
scope.users = response.data; 
+0

新しいデータがサーバーから送信されるたびに。 –

+0

なぜこのレスポンスを行う必要がありますか.dataは配列をインスタンス化して別のオブジェクトにユーザを指す新しい配列ですか? – shaunhusain

+0

そのテーブルから古い行を削除し、ng-repeatで新しいデータを表示したいとします。 –

0

以下のように新しいデータをプッシュ

scope.users = []; 
scope.users = response.data; 

第2に、スプライスして新しいデータを挿入できます。

//This will recreate the array as well 
scope.users.splice(0, scope.users.length, ...response.data); 

だから、のようになります。このおresponse.dataとユーザーが同じである値を削除しようとしている私はあなたのコメントから想定していますです

http.get("getallusers.do",{ params:{pageno:count,pageSize:2}}).then(function(response) { 
        //First function handles success 
        scope.users = [] 
        scope.users = response.data; 
        //OR 
        scope.users.splice(0, scope.users.length, ...response.data); 
      )} 

UDPATE。

あなたはこのようなことをすることができます。 `OPで、

scope.users = scope.users.filter(function(obj) { 
       return response.data.indexOf(obj) == -1; }); 
+0

ng-repeatで新しいデータを繰り返しますが、古いデータに追加します。私は古い行を削除し、そのテーブルに新しい行を追加したい –

+0

@ RajanikantaPradhanあなたはそのresponse.dataの古いデータを取得していますか?何か他のことをして、古いデータをユーザーから削除すると言ったからです。更新された回答を確認する – Hey24sheep

0

あなたの現在のコード` scope.users = response.dataあたりとして$scope.users = response.data;

$scope.users = response.data; 
    $scope.$apply() 

Working demo

関連する問題