我使用Firebase API在Angular中创建了一个应用程序。 这个概念是用户登录创建一个菜(在伪造的菜肴树结构中),菜的referenceId保存在锻造用户的json树(与'菜'的层次结构相同)中。
在Angular中,我创建了一个范围数组,然后使用getUserDishes()方法填充该数组。 因此,在HTML中仅显示该特定用户创建的菜肴。
详情如下:
锻造:
"dishes" : {
"-JVrqxyCG16PAJ0te8VM" : {
"category" : "-JWLmke98kFmc20h8qsF",
"description" : "Meat balls lamb, with onion,roasted garlic,olive oil,herbs,spice sauce brava.",
"name" : "Balls Lamb with Brava Sauce",
"owner" : "User A",
"photo" : "Image_URL_1",
"price" : 395
},
"-JVrrFShm8cR_YbzGEWo" : {
"category" : "-JWLmBkPBMJUUiAmcuKa",
"description" : "Typical tapa in Spain with fried eggs,ptoatoes,chorizo,ham,garlic bread.",
"name" : "Eggs Sevillana",
"owner" : "User A",
"photo" : "Image_URL_2",
"price" : 325
},
"-JVvY3yQcKia6J9-85ku" : {
"description" : "Example Description",
"name" : "Example Dish",
"owner" : "User B",
"photo" : "Image_URL_3",
"price" : 100
}
},
"users" : {
"User A" : {
".priority" : "simplelogin:72",
"dishes" : {
"-JVrqxyCG16PAJ0te8VM" : "-JVrqxyCG16PAJ0te8VM",
"-JVrrFShm8cR_YbzGEWo" : "-JVrrFShm8cR_YbzGEWo"
}
"User B" : {
".priority" : "simplelogin:73",
"dishes" : {
"-JVvY3yQcKia6J9-85ku" : "-JVvY3yQcKia6J9-85ku"
}
}
Controler Logic:
var dishesref = new Firebase(FIREBASE_URL + 'dishes');
var usersref = new Firebase(FIREBASE_URL + 'users');
.
.
.
getUserDishes: function () {
var dishes = {};
if (User.signedIn()) {
var user = User.getCurrent();
var userObj = $firebase(usersref.child(user.username)).$asObject();
userObj.$loaded( function () {
angular.forEach(userObj.dishes, function(dishId) {
dishes[dishId] = $firebase(dishesref.child(dishId)).$asObject();
});
});
}
return dishes;
},
角色代码
<div ng-repeat="(categoryId, category) in categories">
<h1>{{category.name}}</h1>
<li ng-animate="'animate'" class="artist cf" ng-repeat="(dishId, dish) in dishes | filter: query | orderBy: artistOrder:direction">
<!-- <div ng-repeat="(categoryId, category) in categories"> -->
<div ng-if="dish.category === categoryId">
<a href="" ng-href="#/details/{{dishId}}">
<img ng-src="{{dish.photo}}" alt="Photo of {{dish.name}}">
<div class="info">
<h2>{{dish.name}}</h2>
<h2>{{dish.Id}}</h2>
<h3>{{dish.price}} INR</h3>
</div>
</a>
</div>
<!-- </div> -->
</li>
</div>
现在我试图在Firebase的Android API中复制相同的概念。 我已成功修改android chat example以显示所有菜肴(即,“菜肴”中的所有项目均可从锻造中看到)。 这种方法需要一些改变。
我只需要显示来自用户A的菜肴。 为此,我需要在Android中复制上述概念,该概念已经在angular中实现。
您可以找到Android项目存储库:Click Here
有关如何在Android中实现此目的的任何提示吗?谢谢。