我想從下面的json數據中檢索名稱和描述字段,然後將其附加到頁面上。目前我可以確定只能看到信息。這是我嘗試過的,它不起作用。我相信這是遠遠不夠正確的,但我想要朝正確的方向推進。使用json數據創建下拉列表
mainApp.controller('drpdwnCtrl',['$scope','$http' , function ($scope, $http) {
// $scope.ChoreList = null;
//Declaring the function to load data from database
$scope.fillChoreList = function() {
$http({
method: 'GET',
url: 'https://tiy-homeshare.herokuapp.com/homes/26/completed_chores', // Travis'
// data: $scope.ChoreList,
headers: {Authorization: JSON.parse(localStorage.getItem("user_token")) }
}).success(function (result) {
$scope.completeChoreList = result.chores.completed;
console.log($scope.completeChoreList);
});
};
// Calling the function to load the data on pageload
$scope.fillChoreList();
}]); // end drpdwnCtrl
{
"chores": {
"completed": [
{
"id": 61,
"chore_creator_id": 97,
"home_id": 26,
"name": "empty",
"description": "trash",
"bill_value": null,
"votes": null,
"thumbs_up": null,
"created_at": "2016-07-31T20:43:06.013Z",
"completed_at": "2016-07-31T20:46:31.604Z",
"chore_completer_id": 97,
"chore_assignee_id": null,
"avatar": null,
"chore_xp": 40,
"completed": true
},
<div ng-controller="drpdwnCtrl">
<select ng-options="chores in completeChoreList" ng-model="selectedChores" >
<option value="" label="Select a chore"></option>
</select>
</div>
好問題。這對我們的認證系統很有用。 – trav