【发布时间】:2016-12-16 00:24:38
【问题描述】:
我正在尝试按位置过滤我的结果。
但是,由于结果不是数组,因此 orderby 会立即破坏页面。我怎样才能改变这个?我被这个困住了。
我是这样做的:
<div ng-repeat="cat in content | orderBy : 'pos'" class="animated zoomIn">
和控制器:
firebase.database().ref("v3/standalonelist/" + catId.toLowerCase()).on('value', function(snapshot) {
$timeout(function() {
$scope.content = snapshot.val();
console.log($scope.content);
})
});
$scope.content 返回这个对象:
{
"Bar One" : {
"bgurl" : "https://domain.com/aa/bars/list/bar.jpg",
"name" : "Bar One",
"subtitle" : "Cheers",
"pos", 2
},
"Bar Two" : {
"bgurl" : "https://domain.com/aa/bars/list/bar.jpg",
"name" : "Bar Two",
"subtitle" : "Cheers",
"pos", 1
}
}
我得到这个错误:
[orderBy:notarray] 预期的数组但已收到:[THE OBJECT ABOVE]
【问题讨论】:
-
错误为真,这是一个包装另一个对象的对象。你的内容应该是这样的: $scope.content = [ { "bgurl" : "domain.com/aa/bars/list/bar.jpg", "name" : "Bar One", "subtitle" : "Cheers", "pos", 2 }, { " bgurl" : "domain.com/aa/bars/list/bar.jpg", "name" : "酒吧二", "subtitle" : "干杯", "pos", 1 } ]
标签: html angularjs firebase firebase-realtime-database