如何在點擊單選按鈕時過濾category values
?如何過濾angularjs中單選按鈕的值?
- 其實我要過濾類別值。
對於實施例: - 在 plunker我們已經顯示使用的data-ng-bind
類別值。有兩個單選按鈕可用,1.Moral Ethics
2. Religion & Culture
。如果我們點擊第一個單選按鈕moral ethics
它應該是filter
只有moral ethis values
,如果我們點擊第二個單選按鈕religon & Culture
它應該是filter
只有religon & Culture values
。 。
我的HTML單選按鈕: -
<div class="col-md-3">
<label class="green"><input type="radio" name="myquestion" data-ng-model="myquestion.category" value="myquestion" ><span>Moral Ethics</span></label>
</div>
<div class="col-md-3">
<label class="green"><input type="radio" name="culture" data-ng-model="culture.category" value="culture" ><span>Religion & Culture</span></label>
</div>
我的HTML過濾器: -
ng-repeat="question in questions | filter: myquestion | filter:culture"
我的HTML數據: -
<div ng-repeat="question in questions | filter:myquestion | filter:culture">
<small>
<span >{{$index + 1}}.</span>
<span data-ng-bind="question.category"></span>
</small>
</div>
我控制器數據: -
$scope.questions = [
{
"_id":"5863d3aaacaeddc00663bc07",
"user":{
"roles":[
"admin"
],
"profileImageURL":"./modules/users/client/img/profile/uploads/ac4fbab396c2f725ed5211524f171136"
},
"friend_tag":[
],
"emotion":"Confused",
"category":"Religion & Culture",
"created":"2016-12-28T15:00:58.777Z"
},
{
"_id":"5863d3aaacaeddc00663bc07",
"user":{
"roles":[
"admin"
],
"profileImageURL":"./modules/users/client/img/profile/uploads/ac4fbab396c2f725ed5211524f171136"
},
"friend_tag":[
],
"emotion":"Confused",
"category":"Moral Ethics",
"created":"2016-12-28T15:00:58.777Z"
},
{
"_id":"5863d3aaacaeddc00663bc07",
"user":{
"roles":[
"admin"
],
"profileImageURL":"./modules/users/client/img/profile/uploads/ac4fbab396c2f725ed5211524f171136"
},
"friend_tag":[
],
"emotion":"Confused",
"category":"Environment & Health",
"created":"2016-12-28T15:00:58.777Z"
},
{
"_id":"5863d3aaacaeddc00663bc07",
"user":{
"roles":[
"admin"
],
"profileImageURL":"./modules/users/client/img/profile/uploads/ac4fbab396c2f725ed5211524f171136"
},
"friend_tag":[
],
"emotion":"Confused",
"category":"Environment & Health",
"created":"2016-12-28T15:00:58.777Z"
},
{
"_id":"5863d3aaacaeddc00663bc07",
"user":{
"roles":[
"admin"
],
"profileImageURL":"./modules/users/client/img/profile/uploads/ac4fbab396c2f725ed5211524f171136"
},
"friend_tag":[
],
"emotion":"Confused",
"category":"Religion & Culture",
"created":"2016-12-28T15:00:58.777Z"
},
{
"_id":"5863d3aaacaeddc00663bc07",
"user":{
"roles":[
"admin"
],
"profileImageURL":"./modules/users/client/img/profile/uploads/ac4fbab396c2f725ed5211524f171136"
},
"friend_tag":[
],
"emotion":"Confused",
"category":"Religion & Culture",
"created":"2016-12-28T15:00:58.777Z"
},
{
"_id":"5863d3aaacaeddc00663bc07",
"user":{
"roles":[
"admin"
],
"profileImageURL":"./modules/users/client/img/profile/uploads/ac4fbab396c2f725ed5211524f171136"
},
"friend_tag":[
],
"emotion":"Confused",
"category":"Moral Ethics",
"created":"2016-12-28T15:00:58.777Z"
}
]
- 請找我plunker參考,幫助我..請更新plunker也知道確切的解決方案...謝謝。複選框象下面這樣
這是非常簡單的分配公共視圖模型單選按鈕,並將該值分配給過濾器。看看這個http://plnkr.co/edit/zzAwBXysnoFCZQyqKqF0?p=preview –
http:// stackoverflow。com/questions/15868248/how-to-filter-multiple-values-or-operation-in-angularjs –
感謝您的寶貴答案... –