這可能是一個簡單的解決方案,但它使我瘋狂。我有一行代碼,我想在屬性中引用我的數組。我是AngularJS的新手,所以這可能是一個非常愚蠢的問題。在定義的對象中引用時未定義數組
陣列被稱爲例如:
console.log($scope.pickupleague.players);
這將返回:未定義
思考,我的目標$ scope.pickupleague不工作,我呼籲:
console.log($scope.pickupleague);
但是,這會返回我正在尋找的所有內容。對象中有7個獨立的項目。現在我沒有爲我的功能做任何額外的工作。整個事情就是這樣:
$scope.setSubscribedPlayers = function(leagueDetails) {
console.log($scope.pickupleague.players);
};
一旦設置了$ scope.pickupleague,我就調用這個函數。再次,據我所知,沒有什麼瘋狂的事情發生。該功能看起來像這樣:
$scope.findOne = function() {
$scope.pickupleague = Pickupleagues.get({
pickupleagueId: $stateParams.pickupleagueId
});
$scope.listPlayers = $scope.setSubscribedPlayers($scope.pickupleague);
};
對此的任何幫助將是偉大的。我很難過,我覺得像這樣的事情,這應該是一個非常簡單的解決方案。
非常感謝。
編輯 - 添加$ scope.pickupleague
__v: 17
_id: "55323371b2873f32099aa435"
address: "1234 Dufferin Street"
city: "Thornhill"
contactname: "Mike L"
cost: "30"
country: "Canada"
created: "2015-04-18T10:35:29.939Z"
description: "This is just a game for some beginners to get together and play."
email: "[email protected]"
name: "Friday Night Hockey"
phone: "416-123-4433"
players: Array[7]
0: Object
_id: "5540b318ffe8b25b749da4fd"
playerID: "553fda45d014e77bc659d16f"
1: Object
_id: "5540b3c5ffe8b25b749da4fe"
playerID: ""
2: Object
_id: "5540b3eeffe8b25b749da4ff"
playerID: ""
__proto__: Object
3: Object
_id: "5540b434ffe8b25b749da500"
playerID: ""
__proto__: Object
4: Object
_id: "5540b4efffe8b25b749da501"
playerID: "553fda45d014e77bc659d16f"
__proto__: Object
5: Object
_id: "5540b567ffe8b25b749da502"
playerID: "553fda45d014e77bc659d16f"
__proto__: Object
6: Object
_id: "5540b5adffe8b25b749da503"
playerID: "552af744291bddc5b98934c0"
length: 7
__proto__: Array[0]
postalcode: "1a2 b3c"
province: "Ontario"
skillLevel: "Rookie"
time: "11:00pm - 12:00 am"
我想你需要調用數組的元素,而不是數組本身? – mcraen
您的'.findOne()'函數設置了一個名爲「listPlayers」的屬性,但是您的原始語句正在尋找名爲「players」的屬性。 – Pointy
請發佈對象內容的示例$ scope.pickupleague – devconcept