Javascript 保存并获得Firebase collection AngularFire 0.6.0中物品的$priority
比如说我有一系列的物品Javascript 保存并获得Firebase collection AngularFire 0.6.0中物品的$priority,javascript,angularjs,firebase,angularfire,Javascript,Angularjs,Firebase,Angularfire,比如说我有一系列的物品 var itemsRef = new Firebase("https://example.firebaseio.com/items"); $scope.items = $firebase(itemsRef); 我想用$priority $scope.items["thing"] = {name:'The Thing'}; $scope.items["thing"].$priority = 1; $scope.items.$save("thing"); 到目前为止还
var itemsRef = new Firebase("https://example.firebaseio.com/items");
$scope.items = $firebase(itemsRef);
我想用$priority
$scope.items["thing"] = {name:'The Thing'};
$scope.items["thing"].$priority = 1;
$scope.items.$save("thing");
到目前为止还不错-我可以在我的收藏中看到新的物品
现在,让我们把它取出来,找出我刚才分配给它的$priority
:
var thingRef = new Firebase("https://example.firebaseio.com/items/thing");
$scope.thing = $firebase(thingRef);
$scope.thing.$on("loaded", function() {
console.log($scope.thing);
});
这显示了控制台中的Firebase对象,没有为其分配$priority
但是,如果我们这样做:
//After saving the "thing" $priority
$scope.items.$on("loaded", function() {
console.log($scope.items);
});
您将看到子节点及其$priority
$scope.items["thing"] = {name:'The Thing'};
$scope.items["thing"].$priority = 1;
$scope.items.$save("thing");
保存和获取Firebase收集项目优先级的正确方法是什么?这是一个已解决的错误:
这应该可以,除非对save()的调用是调用
update
,而这不会保持优先级。您可以尝试使用orderByPriority
过滤器查看过滤器返回的数组中是否反映了优先级吗?@Anant有趣的是,当我console.log($scope.items)
在$scope.items.$on(“加载”)之后
回调我看到$priority
作为thing
子节点的属性附加。$priority
是否仅在获取包含具有$priority
的子级的父级时返回?啊,确实可能是这样。我们查看getPriority()在解析快照时是否返回任何内容,如果快照不存在,我们不会为那个特定的节点包含它。@a现在我们已经建立了一个$priority
被保存到thing
的事实,我想我们回到了原来的问题,那就是---你是否能够使用items/thing
ref直接获取thing
的$priority
,你应该能够。如果你不是,那很可能是个bug。你能在Github的angularFire下提交一份吗?谢谢