如何在数组中使用数组中的ng-repeat

时间:2017-11-19 18:11:32

标签: javascript arrays angularjs datatable

我有这种形式的数据,employeeObjects是一个数组,内部有11个数组

employeeObjects (11) [Array(11), Array(11), Array(11), Array(11), 
 Array(11), Array(11), Array(11), Array(11), Array(11), Array(11), 
  Array(11)]

在employeeobjects中形成数组是

Array(11)
  0 :35
  1:"<div class="media"><img ng-src="app/img/default-user.png" 
  alt="Image" class="img-responsive img-rounded" err-
  src="app/img/default-user.png" 
  onerror="this.onerror=null;this.src=app/img/img-loader.gif"> </div>"
  2:"agent3@email.com"
  3: "agent three"
  4: "agent3@email.com"
  5:"+919098909890"
  6:"iOS"
  7:"3.1.6"
  8:"EagleView"
  9:"<span class="font-size-small font-medium"  
   style="color:#999999">Offline</span>"
  10:"<label class="switch switch custom-switch"  aria-
   hidden="false"><input type="checkbox" ng-
  model="agent_approve[$index]" ng-
  click="agent_status(agent_approve,35)" class="ng-pristine ng-
  untouched ng-valid" aria-checked="true" aria-invalid="false">↵                            
  <span></span> </label>"
 length:11
 __proto__:Array(0)
 1:(11) [34, "<div class="media"><img ng-src="app/img/default-us…
 ror=null;this.src=app/img/img-loader.gif"> </div>", 
 "agent2@email.com", "agent two", "agent2@email.com", "+919098909890", 
 "Android", "3.2.3", "EagleView", "<span class="font-size-small font-
medium" style="color:#63AE0C">Idle</span>", "<label class="switch 
switch custom-switch"  aria-h…   <span></span>↵                        
</label>"]
2:(11) [33, "<div class="media"><img ng-src="app/img/default-us…
ror=null;this.src=app/img/img-loader.gif"> </div>", 
"agent1@email.com", "agent one", "agent1@email.com", "+919098909890", 
"iOS", "3.1.6", "EagleView", "<span class="font-size-small font-
medium" style="color:#63AE0C">Idle</span>", "<label class="switch 
switch custom-switch"  aria-h…   <span></span>↵                        
</label>"]

这是我以这种形式获取数据的演示。 实际上我有数据表格式的数据。然后我把它转换成数组。现在建议我如何在html页面上呈现

1 个答案:

答案 0 :(得分:0)

虽然这肯定不是在您的视图中显示数据的理想方式,但您可以使用ng-repeat$sce在视图中呈现您的内容。我假设你有像这样的控制器中的数据

// code in your controller
$scope.employeeObj = [[{obj1}, {obj2}..], [{obj1}, {obj2}..], ...]

// code in view
<div ng-repeat="obj in employeeObj">
    <div ng-repeat="item in obj" ng-bind-html="item"></div>
</div>