我是angularjs的新手,我试图将一个对象从一个函数返回到ng-repeat。
<div ng-controller="homeCtrl">
<div ng-init="getProductCategories()">
<div ng-repeat="productCategory in productCategories">
<span>{{productCategory._id}}</span>
<span>{{productCategory.name}}</span>
<div ng-click="getProducts(productCategory._id)">category</div>
<div ng-repeat="product in products">
{{product.title}}
</div>
</div>
</div>
和控制器功能是::
.controller('homeCtrl', function($scope,$appService) {
$scope.getProductCategories = function(){
var query={"table":"product_categories"};
query.columns=["name","description"];
var queryParams ={query:JSON.stringify(query), "ask":ASK, "osk":OSK};
var serviceUrl = "/rest/data";
$appService.getDataFromJQuery(serviceUrl, queryParams, "GET", "JSON",function(productCategoryData){
$scope.productCategories = productCategoryData.data;
}, function (jqxhr, error) {
})
return $scope.productCategories;
}
$scope.getProducts = function(categoryid) {
var query={"table":"products"};
query.columns=["cost","description","image","name","short_description",{"expression":"product_category","columns":["_id","name"]}];
query.filter = {"product_category":categoryid};
var queryParams ={query:JSON.stringify(query), "ask":ASK, "osk":OSK};
var serviceUrl = "/rest/data";
$appService.getDataFromJQuery(serviceUrl, queryParams, "GET", "JSON",function(productData){
$scope.products = productData.data;
}, function (jqxhr, error) {
})
return $scope.products;
}
});
它不会显示我想要的数据,并且会在每次加载页面时崩溃我的浏览器。
显示
类别1 产品a产品b
类别2 产品a产品b
而不是 第1类 产品a产品b类别2 产品c产品d
答案 0 :(得分:1)
您正在使用两次ng-repeat,请尝试使用ng-repeat-start和ng-repeat-end 例如 -
<div ng-repeat-start="thing in app.things">{{ thing }}</div>
<div ng-repeat-end=""></div>
您可以在此处参考以获取更多信息
[http://www.thinkster.io/angularjs/mR4rB2Xu4N/angularjs-ng-repeat-start][1]