在 AngularFire 中使用$priority与$push
Using $priority with $push in AngularFire
我尝试使用以下代码将数据推送到Firebase,它工作正常。
var firebaseObj = new Firebase("https://burning-fire-1723.firebaseio.com/Articles");
var fb = $firebase(firebaseObj);
fb.$push({
title: "title",
post: "post",
emailId: "mymail@gmail.com"
}).then(function(ref) {
console.log(ref);
}, function(error) {
console.log("Error:", error);
});
接下来,为了从Firebase获取特定记录,我需要在推送数据时为emailId字段分配优先级。但我真的不知道该怎么做。任何帮助将不胜感激。
这应该为您完成。
var user = "mymail@gmail.com";
var firebaseObj = new Firebase("https://burning-fire-1723.firebaseio.com/Articles");
var fb = $firebase(firebaseObj);
fb.$push({
title: title,
post: post,
emailId: user,
'.priority': user
}).then(function(ref) {
console.log(ref);
$location.path('/welcome');
}, function(error) {
console.log("Error:", error);
});
答案来自本教程。
相关文章:
- NodeJS API调用中Array中的Push和Pull元素
- Push方法显示错误
- Array.push导致程序出错
- Firebase“;未捕获的类型错误:myDataRef.push不是函数;
- $$hashKey在Angular中push()新对象时未生成新值
- 带array.push()的双方括号---JavaScript
- 使用$http的angular js中的JSON数据-data.push()
- 为什么push方法没有'在这种情况下不起作用:[].推
- Flexbox导致adsense错误:;adsbygoogle.push()错误:没有可用宽度为0的插槽大小;
- 为什么这个 .push 不起作用?(JavaScript)
- 检测未绑定的本机函数,如“Array.push”
- Javascript:如何对属性变量(例如var.hello.push)执行数组方法?太习惯AS3了
- 向 Firebase “push” 方法添加时间戳
- TypeError: matrix[y].push 在尝试使用 javascript 创建 2D 数组时不是一个函数
- dataLayer.push() 返回值含义
- Javascript:push 不是数组的函数
- JavaScript:为什么 array.push() 附加两个对象而不是一个对象
- 带有jquery .push的Javascript全局数组在备用函数中返回空数组
- Javascript/jQuery - “无法调用未定义的方法'push'”,而它是定义的
- 在 AngularFire 中使用$priority与$push