【发布时间】:2015-12-18 14:53:12
【问题描述】:
我在使用 ionic 框架中的 angularjs 将我的数据绑定到我的视图时遇到了一些问题。
这是我的 controller.js:
.controller('InventoryCtrl', function($scope, Category, Inventory) {
$scope.categories = Category;
$scope.searchInventory = function(category){
var word = category.Category;
var ref = new Firebase('https://vivid-heat-2430.firebaseio.com/');
var invenRef = ref.child('Inventories');
var prodRef = invenRef.child('Products');
invenRef.orderByChild("Products").on("child_added", function(snapshot) {
var data = snapshot.val();
var store = data.Inventory;
var prod = data.Products;
var test = Object.keys(prod);
for( var i = 0; i < test.length; i++){
if (test[i] == word) {
console.log(test[i]);
console.log("Storage place: " + data.Inventory + " Datum inventaris: " + data.Date);
$scope.show= test[i];
};
};
});
};
})
在这里,我从我的阵列中获取我的产品。那我比较一下。它会给我匹配的对象,它也会给我它所属的存储位置。我可以在我的控制台中记录它。但是当我试图将它绑定到我的视图时。它什么也没给我。
这是我的 index.html:
<ion-content>
<p><b>Zoek categorie</b></p>
<ion-scroll direction="y" >
<div style="max-height: 300px" ng-controller="InventoryCtrl">
<ion-list>
<ion-radio ng-repeat="category in categories" class="item-accordion" ng-model="checked.check" value="{{category.Category}}" ng-click="searchInventory(category)">
<p>{{category.Category}}</p>
</ion-radio>
<br>
</ion-list>
</div>
<div>
<ion-list>
<ion-item>
{{show}}
</ion-item>
</ion-list>
</div>
</ion-scroll>
</ion-content>
我不明白我做错了什么……是因为我的$scope.show 还在.on 方法中吗?
【问题讨论】:
标签: javascript angularjs ionic firebase angularfire