Angularjs 带变量的角度范围
假设我有来自AngularJS的教程代码Angularjs 带变量的角度范围,angularjs,Angularjs,假设我有来自AngularJS的教程代码 var myApp = angular.module('myApp', []); myApp.controller('myCtrl', function ($scope) { $scope.phones = [ {'name': 'Nexus S', 'snippet': 'Fast just got faster with Nexus S.'}, {'name': 'Motorola XO
var myApp = angular.module('myApp', []);
myApp.controller('myCtrl', function ($scope) {
$scope.phones = [
{'name': 'Nexus S',
'snippet': 'Fast just got faster with Nexus S.'},
{'name': 'Motorola XOOM with Wi-Fi',
'snippet': 'The Next, Next Generation tablet.'},
{'name': 'MOTOROLA XOOM',
'snippet': 'The Next, Next Generation tablet.'}
];
});
现在让我们假设我想用一个包含我的信息的数组替换所有声明“name”和“snippet”的部分。这可能吗?据我所知,您的问题是JavaScript对象是否可以包含嵌入式数组。答案是肯定的 大概是这样的:
var myApp= angular.module('myApp', []); myApp.controller('myCtrl', function ($scope) {
$scope.phones = [
{'name': ['string1','string2','string3','string4'],
'snippet': 'Fast just got faster with Nexus S.'},
{'name': [1,2,3,4,5],
'snippet': 'The Next, Next Generation tablet.'},
{'name': [{'prop':'value'},{'prop':'value2'},{'prop':1},{'prop':2} ],
'snippet': 'The Next, Next Generation tablet.'} ]; });
您的$scope.phones已经是一个数组。我用字符串数组替换了first items name属性。第二个items name属性是一个数字数组。第三个items name属性包含一个对象数组
[代码是在浏览器中编写的,未经测试,但从概念上讲这是正确的]试试看,如果您有问题,请回答具体问题。你的问题的答案是肯定的。是的,但如果你先问这个问题,你可能会研究JavaScript,了解对象、它们的属性和值是什么。