嗨,我有下一个问题:
在我看来,我调用了一个函数 prepareDynamicData(itemMenu);
<div ng-repeat="itemMenu in menuDetailsData.categories" class="headDetails fontH2">
<div style="display: none">{{prepareDynamicData(itemMenu)}}</div>
<a href="#" ng-show="dynamicData.expand">{{itemMenu.name}}</a>
<div ng-repeat="cat in dynamicData.data">
<p>{{cat.name}}</p>
<div class="articles">
<div ng-repeat="art in cat.items" class="article">
<div class="price">
<div></div>
<span><i>₪</i>{{art.price}}</span>
</div>
<div class="artDescr">
<span class="fontTitle">{{art.title}}</span>
<p class="fontDetails">{{art.description}}</p>
</div>
</div>
</div>
</div>
</div>
我知道顶部循环仅重复 2 次(已验证),但函数 prepareDynamicData(itemMenu) 调用了 4 次,不知道为什么!?这是我的控制器:
function MenuItemCtrl($scope, $routeParams, $http, $location, sharedData) {
if (sharedData.getMenuDetails() == null) {
$location.path('/menu');
return;
}
else {
$scope.menu = sharedData.getMenu();
$scope.menuDetailsData = sharedData.getMenuDetailsData($routeParams.itemId);
}
$scope.dynamicData = {
data : new Array(),
expand : false
};
$scope.prepareDynamicData = function (itemMenu) {
if (itemMenu.items != null) {
$scope.dynamicData.data[0] = itemMenu;
$scope.dynamicData.expand = false;
}
else {
$scope.dynamicData.data = itemMenu.categories;
$scope.dynamicData.expand = true;
}
}
}
你能帮我解释一下为什么会这样吗!谢谢