在firebase中,我想创建一个URL,单击该URL会将某人的名字添加到firebase数据结构中的列表中。如果无法做到这一点,请提供在单击时将该人标记为在firebase中已获批准的URL。
例如,考虑以下结构:
-Sample (which would be at https://Sample.firebaseio.com)
-Users
我想产生以下
-Sample (which would be at https://Sample.firebaseio.com)
-Users
Liz_Smith
Shanna_Oreily
通过创建这样的URL:
https://Sample.firebaseapp.com/users/Liz_Smith
https://Sample.firebaseapp.com/users/Shanna_Oreily
我认为这样的事情是不可能的,因为就好像使用URL进行推送一样。如果不可能,我想激活以下URL,这意味着它们实际上作为URL存在
https://Sample.firebaseapp.com/users/Liz_Smith
https://Sample.firebaseapp.com/users/Shanna_Oreily
当某人访问该URL时,该人将被更新为已批准,这将变为:
-Sample (which would be at https://Sample.firebaseio.com)
-Users
Liz_Smith
approved: False
Shanna_Oreily
approved: False
变成这样的东西:
-Sample (which would be at https://Sample.firebaseio.com)
-Users
Liz_Smith
approved: True
Shanna_Oreily
approved: True
我认为这样的事情是不可能的,因为就好像使用URL进行推送一样。
您可以在Firebase中存储URL。
在这种情况下,您可以为定位标记添加事件监听器。单击后,可以将数据设置为Firebase。如果您还为Firebase中的用户位置附加了侦听器,则可以将这些链接实时附加到页面。
以下是使用jQuery完成的示例,但可以轻松地将其适应您所使用的任何过程或框架。
var fbRef = new Firebase('https://firenode.firebaseio.com/'),
userRef = fbRef.child('users'),
appUrlBase = 'https://myapp.firebaseapp.com/',
links = $('#people-list > li a'),
urlList = $('#url-list');
// create click handlers for every link
$.each(links, function(key, link) {
var $link = $(link),
name = $link.text(),
url = appUrlBase + name;
$link.on('click', function(e) {
userRef.child(name).set({
approvedUrl: url // <- this is a URL
});
});
});
// helper function for creating lis with a tags
function createLi(url) {
var li = $('<li></li>');
li.append('<a href="' + url + '">' + url + '</a>');
return li;
}
// listen for the additions to the users location
// when items are added we can append to the list
userRef.on('child_added', function(snap) {
var url = snap.val().approvedUrl;
elem = createLi(url);
urlList.append(elem);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句