角度JS javascript数组表示法
我想知道什么样的javascript对象需要能够调用像这样的符号角度JS javascript数组表示法,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我想知道什么样的javascript对象需要能够调用像这样的符号{{item.descriptions.comments} 代码是这样的 <div ng-app="manyminds" ng-controller="MainCtrl"> <div class="idea item" ng-repeat="item in items" isoatom> <br /> {{item.descriptions.comments}} </
{{item.descriptions.comments}
代码是这样的
<div ng-app="manyminds" ng-controller="MainCtrl">
<div class="idea item" ng-repeat="item in items" isoatom>
<br />
{{item.descriptions.comments}}
</div>
</div>
angular.module('manyminds', [], function() {}).filter('range', function() {
return function(input, min, max) {
var range = [];
min = parseInt(min); //Make string input int
max = parseInt(max);
for (var i=min; i<=max; i++)
input[i] && range.push(input[i]);
return range;
};
});
function MainCtrl($scope)
{
$scope.items = [
{descriptions:[
{
comments: [
'comment A in item 0',
'comment B in item 0'
]
},
{
comments: [
'comment A in item 1',
'comment B in item 1',
'comment C in item 1',
'comment D in item 1'
]
}
]},
{descriptions:[
{
comments: [
'comment A in item 0',
'comment B in item 0'
]
},
{
comments: [
'comment A in item 1',
'comment B in item 1',
'comment C in item 1',
'comment D in item 1'
]
}
]},
];
}
{{item.descriptions.comments}}
angular.module('manyminds',[],function(){}).filter('range',function()){
返回功能(输入、最小值、最大值){
var范围=[];
min=parseInt(min);//使字符串输入为int
max=parseInt(max);
对于(var i=min;i假设项目、描述和注释都应该是数组,如果您试图显示每个描述的注释,则可以嵌套ng重复:
<div ng-app="manyminds" ng-controller="MainCtrl">
<div class="idea item" ng-repeat="item in items" isoatom>
<div ng-repeat="description in item.descriptions">
<div ng-repeat="comment in description.comments">
{{ comment }}
</div>
</div>
</div>
</div>
{{comment}}
您设置了$scope.items
,并尝试通过{{item}}
访问它,但这不起作用
使用$scope.item
或使用模板中的{{items}访问它。您可以执行以下操作:
基本上是嵌套的ng repeat
这可能是您需要的物品:
$scope.items = [
{
name:'item1',
descriptions: [
{
name:'description1',
comments:['commentary1','commentary2']
},
{
name:'description2',
comments:['commentary1','commentary2']
}
]
},
{
name:'item2',
descriptions: [
{
name:'description1',
comments:['commentary1','commentary2']
},
{
name:'description2',
comments:['commentary1','commentary2']
}
]
}];
视图应该是这样的:
<div ng-repeat="item in items">
<h1>{{item.name}}</h1>
<div ng-repeat="description in item.descriptions">
<h3>{{description.name}}</h3>
<div ng-repeat="comment in description.comments">
<p>{{comment}}</p>
</div>
</div>
</div>
{{item.name}
{{description.name}}
{{comment}}
{item:{descriptions:{comments:“Hello World!”}}
当然,这只适用于单个项目/描述/评论。这并不能回答问题。若要评论或要求作者澄清,请在其帖子下方留下评论-您可以随时对自己的帖子发表评论,一旦有足够的评论,您就可以发表评论。@apaul34208我感谢您的建议e;)