作者:我的菜菜呀 | 来源:互联网 | 2023-05-17 08:05
Istartedangularjs2daysago()Imcurrentlyaskingmyselfhowtocreateafunctionthatfetch
I started angularjs 2 days ago (...) I'm currently asking myself how to create a function that fetches my firebase data and depending on the child, it returns a string.
我2天前开始使用angularjs(...)我目前正在问自己如何创建一个获取我的firebase数据的函数,并根据子节点返回一个字符串。
Seems pretty simple when I say it, but harder to do...
我说的时候看起来很简单,但更难做到......
I could fetch the data one by one but the problem is that there are a total of 84 childs!!
我可以逐个获取数据,但问题是总共有84个孩子!
My Context The website retrieves from firebase if a person is working night, day or evening, for the 7 days of the week, for 4 weeks in a month (3x7x4 = 84). An example of one of my child is: Saturday1Night: true where "1" means week 1.
我的上下文如果一个人在一天中的7天工作,一天或晚上工作,一个月中的4周(3x7x4 = 84),网站将从firebase中检索。我孩子的一个例子是:Saturday1Night:true,其中“1”表示第1周。
What I tried
我尝试了什么
function getOneDay(currentUserId, key, query, text){
firebase.database().ref().child('Users').child(currentUserId).child(key).once('value').then(function(snapshot) {
/* query is "Saturday1Night" */
if(datasnapshot.$value === null && datasnapshot.id === null) {
/* not working */
text = 'X';
}else{
/* value is "true", person is working */
text = query;
}
})
return text;
}
Now my real question is, how can I, like in java for example, create a function that returns a string? How can I display it in my $scope?
现在我真正的问题是,我怎么能像java一样创建一个返回字符串的函数?如何在$ scope中显示它?
html
HTML
{{s1n}}
angularjs
angularjs
$scope.s1n = text; //??
$scope.s1n = getOneDay(/*uid*/, /*key*/, "Saturday1Night", $scope.s1n) //??
Thank you in advance, have a good night/day!
提前谢谢,祝你有个美好的夜晚!
2 个解决方案