所以我有这个 $scope
来调用 Firebase 中名为 Questions 的表
$scope.questions=$firebaseArray(fireBaseData.refQuestions());
我这样调用数据库
{{questions}}
就是这样显示的
[{"nama":"Perkataan yang saya sampaikan dapat diingat dan berkesan untuk orang lain.",
"nilai":"item7",
"$id":"1",
"$priority":null
},
{"nama":"Saya sering mengucap “terimakasih” atas pertolongan orang lain agar terlihat ramah.",
"nilai":"item6",
"$id":"2", // THIS VALUE THAT I NEEDED
"$priority":null
}]
问题:
我正在寻找的是只调用 $id value
就像 2 是新的 var
或 $scope
所以我不能让他们做题号
因为我需要新的 var
或 $scope
这样的
$scope.questionNo = $firebaseArray(fireBaseData.refQuestions().$id);
$scope.question =;
$scope.totalQuestions = $scope.questions.length;
$scope.currentRoute = $scope.questionNo;
但失败了
最佳答案
你的问题需要一些澄清,但由于 StackOverflow 不允许我发表评论,所以这里......
如果我没理解错的话,您正试图通过它的 $id 访问特定问题,因此您需要执行以下操作:
$scope.questions = $firebaseArray(fireBaseData.refQuestions().orderByChild('$id').equalTo('2'));
$scope.question = $scope.questions[0];
可以查看angularfire docs和 firebase docs on filtering .
但是,如 here 所述,这种情况主要受益于数据库的不同结构。 .如果它是存储它们的 key ,那么通过它们的 $id 访问问题会容易得多,在这种情况下你可以简单地做
$scope.question = $firebaseObject(fireBaseData.refQuestions().child('2'));
关于javascript - 我如何在 Firebase Angularjs 中使用 $id 作为数字或新变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41034445/