我在我的JavaScript中有一個簡單的JSON對象,並且我想在單擊按鈕時對其進行過濾。如何過濾基於哪個複選框被點擊的JSON?
我環顧四周,發現這一點。到目前爲止,我有這樣的:
$scope.myFunc = function(a) {
for(meal in $scope.mealTypes){
var t = $scope.mealTypes[meal];
if(t.on && a.type.indexOf(t.name) > -1){
return true;
}
}
};
$scope.mealTypes = {Breakfast: false, mainMeal:false};
這是我的HTML:
<input id="checkBox" type="checkbox" name="Breakfast" value="Breakfast" data-ng-model="mealTypes.breakfast">
<input id="checkBox" type="checkbox" name="mainmeal" value="Main Meal" data-ng-model="mealTypes.mainMeal">
然後,我的目標是遍歷數組並顯示檢查按下的按鈕(我希望顯示的名稱):
<span ng-repeat="reciepe in reciepes | filter:search" id="filtertag" name="hello">{{ reciepe.type }}
<span id="filtertagRemove">
<a href="google.com">remove</a>
</span>
</span>
JSON:
$scope.reciepes =
[
{
"type": "Breakfast",
"title": "Chili con carne",
"description": "A spicy and fragrant chili with ground beef, kidney beans, tomatoes, onions and garlic. Best served over rice with a dollop of sour cream and some cheese on top.",
"ratings": 4,
"ingredients":
[
{
"vegetable": "40ml"
}
],
"method":
[
{
"1": "In a medium sized stock pot, heat the oil over medium heat. Saute onions, chile peppers andgarlic until soft."
}
]
},
{
"type": "Main Meal",
"title": "Main Meal",
"description": "A spicy and fragrant chili with ground beef, kidney beans, tomatoes, onions and garlic. Best served over rice with a dollop of sour cream and some cheese on top.",
"ratings": 4,
"ingredients":
[
{
"vegetable": "40ml"
}
],
"method":
[
{
"1": "In a medium sized stock pot, heat the oil over medium heat. Saute onions, chile peppers andgarlic until soft."
}
]
}]
基本上,我的目標是在div上顯示覆選框的值,然後過濾數組。我應該怎麼做?
我不知道是按鈕?你有什麼問題? – micronyks