你可以这样做......在演示控制器内的函数中添加这段代码。
$scope.arr = [];
for(let x of [{name:"1st Item",taste:"sweet"},{name:"2nd item",taste:"spicy"}]) {
let newArr = [];
newArr.push(x.name);
newArr.push(function ($itemScope) {
alert($itemScope.item.cost);
});
$scope.arr.push(newArr);
}
然后用 $scope.arr 替换旧的 Alert Cost" 和 "Alert Player Gold" 数组。
$scope.menuOptions = [
['Buy', function ($itemScope) {
$scope.player.gold -= $itemScope.item.cost;
}],
null,
['Sell', function ($itemScope) {
$scope.player.gold += $itemScope.item.cost;
}, function ($itemScope) {
return $itemScope.item.name.match(/Iron/) == null;
}],
null,
['More...', $scope.arr]
];
瞧,你很高兴。
这是工作的codepen示例。 Working examplehttps://codepen.io/anon/pen/jGBJMY?editors=1010