javascript函数不是';在html中没有考虑到
我在一个范围变量中定义了一些JavaScript函数,如下所示:javascript函数不是';在html中没有考虑到,javascript,angularjs,angularjs-scope,Javascript,Angularjs,Angularjs Scope,我在一个范围变量中定义了一些JavaScript函数,如下所示: $scope.salma = { selectedRestaurants: accounts.selectedRestaurants, findAllAccountsByRestaurant: function(restaurant) { angular.forEach(accounts.AllRestaurantAccounts, function(CurrentAllrestaurantAcco
$scope.salma = {
selectedRestaurants: accounts.selectedRestaurants,
findAllAccountsByRestaurant: function(restaurant) {
angular.forEach(accounts.AllRestaurantAccounts, function(CurrentAllrestaurantAccount) {
if(CurrentAllrestaurantAccount.nameRestaurant === restaurant) {
accounts.currentRestaurantNumberAllAccount = CurrentAllrestaurantAccount.accountNumber;
}
});
return accounts.currentRestaurantNumberAllAccount;
},
findAccountsOptInMAIL: function(restaurant) {
angular.forEach(accounts.AllOptInMAILRestaurantAccounts , function(CurrentAllrestaurantAccountOptInMAIL) {
if(CurrentAllrestaurantAccountOptInMAIL.nameRestaurant === restaurant) {
accounts.currentRestaurantNumberOptInMAIL = CurrentAllrestaurantAccountOptInMAIL.accountNumber;
}
});
return accounts.currentRestaurantNumberOptInMAIL;
}
};
<tbody>
<tr ng-repeat="restaurant in salma.selectedRestaurants">
<td>{{ restaurant }}</td>
<td>{{ salma.findAllAccountsByRestaurant(restaurant) }}</td>
<td>{{ salma.findAccountsOptInMAIL(restaurant) }}</td>
</tr>
</tbody>
我在html中调用这些函数,如下所示:
$scope.salma = {
selectedRestaurants: accounts.selectedRestaurants,
findAllAccountsByRestaurant: function(restaurant) {
angular.forEach(accounts.AllRestaurantAccounts, function(CurrentAllrestaurantAccount) {
if(CurrentAllrestaurantAccount.nameRestaurant === restaurant) {
accounts.currentRestaurantNumberAllAccount = CurrentAllrestaurantAccount.accountNumber;
}
});
return accounts.currentRestaurantNumberAllAccount;
},
findAccountsOptInMAIL: function(restaurant) {
angular.forEach(accounts.AllOptInMAILRestaurantAccounts , function(CurrentAllrestaurantAccountOptInMAIL) {
if(CurrentAllrestaurantAccountOptInMAIL.nameRestaurant === restaurant) {
accounts.currentRestaurantNumberOptInMAIL = CurrentAllrestaurantAccountOptInMAIL.accountNumber;
}
});
return accounts.currentRestaurantNumberOptInMAIL;
}
};
<tbody>
<tr ng-repeat="restaurant in salma.selectedRestaurants">
<td>{{ restaurant }}</td>
<td>{{ salma.findAllAccountsByRestaurant(restaurant) }}</td>
<td>{{ salma.findAccountsOptInMAIL(restaurant) }}</td>
</tr>
</tbody>
{{餐厅}
{{salma.findAllAccountsByRestaurant(餐厅)}
{{salma.findAccountsOptInMAIL(餐厅)}
第一个函数在html中生效,但第二个函数没有生效,我不知道为什么。您有什么建议吗?您确定函数返回的结果正确吗?如果
AllOptInMAILRestaurantAccounts
中没有匹配项,您的函数可能会返回undefined。(很难说清楚,如果不知道还有谁修改了帐户
),您是否已进入第二个功能?可能是accounts.CurrentRestaurantNumber OptinMail
正在返回,只是未定义。编辑:我发誓当我写这篇文章时,doldt的评论是看不见的!;)感谢您的回复。这就是问题所在。我还有一个小问题:代码:accounts.restaurants=$scope.$parent.filters.selection;accounts.SelectedRestarants=[];accounts.getRestaurantsNames=function(){angular.forEach(accounts.restaurants,function(currentRestaurant){accounts.selectedRestaurants.push(currentRestaurantsName);}}accounts.getRestaurantsNames();accounts.selectedRestarants变量未填充,我不知道原因