1
如何從$ resoure調用中檢索值並在JS中使用它,不僅僅在我的視圖中使用數據綁定?
我有這樣的JSON:
{
"id": 18,
"name": "adsfadsf",
"type_of_dish": "Tacos",
"cost": "5.95",
"notes": "bla bla bla",
"totalrecipes": 1,
"dish_recipes_attributes": [
{
"recipe_id": 28,
"no_recipe": 1,
"name": "tacos al pastor piña",
"cost_portion": "5.95"
}
]
}
在我的JS
:
$scope.dish = Dish.get({id: $routeParams.id});
我需要得到的價值 「totalrecipes」,我這個嘗試沒有全成:
var totalrecipes = $scope.dish.totalrecipes;
console.log(totalrecipes); //Undefined
console.log($scope.dish); // [object Object]
但在我看來一切正常:
{{dish.totalrecipes}} // 1, It's OK!
偉大的!我已經明白它是如何工作的!謝謝! –
樂意幫忙! :) – helmbert
@IsraelBarba,也請考慮接受這個答案,如果它完全回答你的問題。 ;) – helmbert