在 AngularJS ng-repeat 中使用 2 个数组的数据

Use data of 2 arrays in AngularJS ng-repeat

我目前正在使用 Backendless 数据存储服务进行 Ionic 1 项目。我有一个网页,我需要将我从 Backendless 获得的 2 个不同表格的详细信息显示到列表中。 这是我的代码:

HTML代码:

<ion-view view-title="Your Bookings" ng-controller="GuBookingsCtrl">
<ion-content class="padding">
<ion-refresher pulling-text="Pull to refresh..." on-refresh="doRefresh()">
</ion-refresher>
<ul class="list">
    <li ng-repeat="r in res track by $index" r="r" hotel="hotel" class="item item-button-right">
      <h2>{{hotel.name}}</h2>
      <p>{{r.checkin}} to {{r.checkout}}</p>
      <button class="button button-positive" ng-click="cancel()">
        Cancel
      </button>
    </li>
</ul>
</ion-content>
</ion-view>

JS代码:

angular.module('GuBookingsCtrl.controllers', [])

.controller('GuBookingsCtrl', function($scope, $state) {
var init = function() {
var user = $state.params.user;
$scope.res = [];
$scope.hotel = [];
var whereClause = "guestID = '" + user.objectId + "'";
var queryBuilder = Backendless.DataQueryBuilder.create().setWhereClause( whereClause );
Backendless.Data.of("Bookings").find( queryBuilder )
  .then(function(foundHotels) {
    $scope.res = foundHotels;
    console.log($scope.res);
    for (var i=0;i<$scope.res.length;i++){
      $scope.hotel[i] = Backendless.Data.of("Hotels").findByIdSync( {objectId: $scope.res[i].hotelID} );
    }
    $scope.$apply();
  })
  .catch(function(error) {
    console.log("error" + error.message);
  })
 }
init();
$scope.doRefresh = function () {
  init();
  $scope.$broadcast ('scroll.refreshComplete');
}

$scope.cancel = function() {
console.log("cancel clicked");
}
})

如果您想使用 ngRepeat 组合两个数组,请使用 javascript concat() 函数

像这样:

<div ng-repeat="item in array1.concat(array2)">{{item}}</div>

你需要更多关注这个