2016-11-28 7 views
0

ラジオボタンをクリックしたときにユーザーの詳細をフィルタする方法はありますか?ラジオボタンをクリックしたときのユーザーの詳細をフィルタリングしますか?

Plunker

*実は、私は、リストページで認証ユーザーの質問をフィルタリングしたいので、私はplunkerを作成しました。私が認証されたユーザー(または)の管理者の場合、リストページでのみmyquestionsをフィルタリングしたいと思います。

例については

: - plunkerでdisplayNameTable 1である私がMy Questionラジオボタンをクリックした場合、私の質問だけfilterする必要があるということです。

マイHTMLラジオボタン: -

<input type="radio" name="myquestion" data-ng-model="myquestion.user.displayName" value="myquestion" > 

マイHTMLフィルタ: -

ng-repeat="question in questions | filter: myquestion" 

**My Html Data:-** 

<div ng-repeat="question in questions | filter: myquestion"> 
    <small> 
         Posted on 
         <span data-ng-bind="question.created | date:'mediumDate'"></span> 
         <span data-ng-bind="question.user.displayName"></span> 
        </small> 

    </div> 

私のコントローラのデータ: -

$scope.questions = [ 
{ 
"_id": "583433ddc021a5d02949a51b", 
"user": { 
"_id": "5834336ac021a5d02949a51a", 
"displayName": "mani R", 
"location": "ICF", 
"dob": "1991-10-05T18:30:00.000Z", 
"religion": "Christian", 
"roles": [ 
"user" 
], 
"profileImageURL": "modules/users/client/img/profile/default.png" 
}, 
"__v": 0, 
"upvoters": [], 
"category": "Moral Ethics", 
"content": "Dhoni", 
"title": "which batsman is best in the world?", 
"created": "2016-11-22T12:02:37.376Z" 
}, 
{ 
"_id": "582c34b3ff26bd603e1e5383", 
"user": { 
"_id": "58072aba0f82a61823c434df", 
"displayName": "Table 1", 
"dob": "1991-10-04T18:30:00.000Z", 
"location": "Icf", 
"religion": "Hindu", 
"roles": [ 
"admin" 
], 
"profileImageURL": "./modules/users/client/img/profile/uploads/c756711556ab6864f408697c7a98aedc" 
}, 
"__v": 1, 
"upvoters": [], 
"users": [], 
"comments": [ 
{ 
"created": 1479365394684, 
"email": "[email protected]", 
"name": "Table 1", 
"commentText": "Dhoni" 
} 
], 
"friend_tag": [], 
"emotion": "Confused", 
"category": "Environment & Health", 
"content": "sachin?", 
"title": "who is best player in this world?", 
"created": "2016-11-16T10:28:03.859Z" 
}, 
{ 
"_id": "582c3418ff26bd603e1e5382", 
"user": { 
"_id": "582c1f4b53cf7fec2ddf282e", 
"displayName": "selvam R", 
"dob": "1991-10-04T18:30:00.000Z", 
"roles": [ 
"kp" 
], 
"profileImageURL": "modules/users/client/img/profile/default.png" 
}, 
"__v": 0, 
"upvoters": [], 
"category": "Environment & Health", 
"content": "he is tennis player", 
"created": "2016-11-16T10:25:28.835Z" 
}, 
{ 
"_id": "582ad554714543e037cf3bf2", 
"user": { 
"_id": "58072aba0f82a61823c434df", 
"displayName": "Table 1", 
"dob": "1991-10-04T18:30:00.000Z", 
"location": "Icf", 
"religion": "Hindu", 
"roles": [ 
"admin" 
], 
"profileImageURL": "./modules/users/client/img/profile/uploads/c756711556ab6864f408697c7a98aedc" 
}, 
"__v": 1, 
"upvoters": [ 
"[email protected]" 
], 
"upvotes": 1, 
"category": "Moral Ethics", 
"created": "2016-11-15T09:28:52.403Z" 
}, 
{ 
"_id": "5821e7c667b70aac2b8fdfdc", 
"user": { 
"_id": "58072aba0f82a61823c434df", 
"displayName": "Table 1", 
"dob": "1991-10-04T18:30:00.000Z", 
"location": "Icf", 
"religion": "Hindu", 
"roles": [ 
"admin" 
], 
"profileImageURL": "./modules/users/client/img/profile/uploads/c756711556ab6864f408697c7a98aedc" 
}, 
"__v": 1, 
"upvoters": [ 
"[email protected]" 
], 
"upvotes": 1, 
"category": "Religion & Culture", 
"created": "2016-11-08T14:57:10.354Z" 
} 
] 
  • alt="{{vm.authentication.user.displayName}}"を試しましたが、完全には機能しません。

答えて

0

あなたがしようとしているのは、ログインしたユーザーのdisplayNameのリストベースをフィルタリングすることだったと思いますか?私はあなたがユーザー認証のためのサービスを持っているかどうかはわかりません。私は表1が与えられたログインユーザーであると仮定しています。私はng-changeを使用して、ラジオボタンが変更されて私と私の意見をすべてフィルタリングするかどうかを検出します。私のコントローラ上の

:HTMLの

$scope.authUser = { 
    "_id": "58072aba0f82a61823c434df", 
    "displayName": "Table 1", 
    "dob": "1991-10-04T18:30:00.000Z", 
    "location": "Icf", 
    "religion": "Hindu", 
    "roles": [ 
     "admin" 
    ], 
    "profileImageURL": "./modules/users/client/img/profile/uploads/c756711556ab6864f408697c7a98aedc" 
}; 

<div class="col-md-3" id="donate"> 
     <label class="green"> 
     <input type="radio" name="myquestion" ng-model="myQuestion" value="myquestion" ng-change="stateChange(myQuestion)"> 
     <span>My Questions</span> 
     </label> 
     <label class="green"> 
     <input type="radio" name="myquestion" ng-model="myQuestion" value="all" ng-change="stateChange(myQuestion)"> 
     <span>All</span> 
     </label> 
    </div> 

    <div ng-repeat="question in questions | filter: { user.displayName: searchText }"> 
     <small> 
     Posted on 
     <span data-ng-bind="question.created | date:'mediumDate'"></span> 
     <span data-ng-bind="question.user.displayName"></span> 
     </small> 
    </div> 

私はあなたのplunkrを編集したサンプルを作業のために。ここにリンクをあなたの貴重な答えを http://plnkr.co/edit/U5M29NMfvtY0vTnQyjmT?p=preview

+0

おかげで、それだけでログインしているユーザーからの質問をフィルタリングする必要がありますbutton'我々はonclicking' 'ラジオの'期待私はあそこのラジオボタン、与えている私のplunkerを見てください... 。例えば、 'Table 1'が記録されているということは、' table 1'の詳細は表示が必要なことを意味します。あなたの答えはほぼ終了しました....しかし、ラジオボタンのフィルタメソッドのonclikingが欠落しています。私たちは 'service'も持っていますので、正確な解決策を教えてください.... –

+0

どのような解決策ですか? ...私の「ローカルホスト」では、フィルタはvm.questions | filter:vm.authentication.user.displayName "でこのフィルタの' ng-repeat = "という質問を使って完全に動作していますが、それはフィルタリングする必要がある 'ラジオボタン 'です。私はこれをラジオの入力フィールドにどのように使用していますか...私のプランナーを見て、解決策を更新してください...ありがとう..遅れて返事を申し訳ありません。 –

+0

私は自分の答えを更新しました。 – Vicruz

関連する問題