我有以下数据,我想使用ng重复:
<div id='cssmenu' class="visible-xs" >
<ul>
<li class='active'><a href='#'><span>Doctors</span></a></li>
<li class='has-sub' ><a href='#'><span ng-repeat="doc in doctors">{{doc.patch}}</span></a>
<ul>
<li><a href='#' ng-repeat="doc in doctors"><span>{{doc.doctor}}</span></a></li>
</ul>
</li>
</ul>
</div>
我试图像这样使用它:
{{1}}
当前输出即时获取显示在以下链接中: current output
预期输出即时获取显示在以下链接中: expected output
我做错了什么?现在已经有1个半小时了!答案 0 :(得分:2)
从你的评论中我假设你遇到了JS关联数组的问题,所以这是一个实现的例子:
$scope.doctors=[
{patch:'BARIJPUR',doctors:['RAMA SENA' 'SMRITI IRANI', 'JAGDISH NAIR',]},
{patch:'KIRI', doctors:['ASHISH NAIK', 'SMRITI IRANI', 'SAIRAJ NAIK']},
{patch:'JAMNAGAR', doctors:['RATAN PANDEY', 'RAMAN SHIVOLKAR']}
];
<div id='cssmenu' class="visible-xs" >
<ul>
<li class='active'><a href='#'><span>Doctors</span></a></li>
<li class='has-sub' ng-repeat="doc in doctors"><a href='#'><span>{{doc.patch}}</span></a>
<ul>
<li ng-repeat="doctor in doc.doctors"><a href='#'><span>{{doctor}}</span></a></li>
</ul>
</li>
</ul>
</div>
答案 1 :(得分:0)
你有两个问题:
您应该只创建一个数组:
,而不是创建多个doctor
实体
$scope.doctors=
[
{"patch":"BARIJPUR", "doctors":["RAMA SENA", "SMRITI IRANI","JAGDISH NAIR"]},
{"patch":"Anna", "doctors":["ASHISH NAIK", "SMRITI IRANI", "SAIRAJ NAIK"]},
{"patch":"Peter","doctors":["RATAN PANDEY", "RAMAN SHIVOLKAR"]}
];
ng-repeat
你在错误的地方使用它。它应该应用于<li>
元素 - 基本上你想要重复,而不是<a>
或<span>
:
<div id='cssmenu'>
<ul>
<li class='active'><a href='#'><span>Doctors</span></a></li>
<li ng-repeat="doc in doctors" class='has-sub'><a href='#'><span>{{doc.patch}}</span></a>
<ul>
<li ng-repeat="doc in doc.doctors"><a href='#'><span>{{doc}}</span></a></li>
</ul>
</li>
</ul>
演示plnkr
答案 2 :(得分:0)
<div class="row" ng-repeat="doc in doctors">{{doc.patch}}
<div class="cell" ng-repeat="cell in doc.doctor">{{cell}}
</div>
</div>
试试这个
答案 3 :(得分:0)
<div class="row" ng-repeat="doc in doctors">{{doc.patch}}
<div class="cell" ng-repeat="cell in doc.doctor">{{cell}}
</div>
</div>
是的,这对我有用!完成了!解决!