gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 03:33:56 31 4
gpt4 key购买 nike

我目前正在开发一个 Ionic 1 项目,利用 Backendless 数据存储服务。我有一个网页,需要将来自 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>

您需要更多信息,请关注此 looping multiple arrays simultaneously with ng-repeat

关于javascript - 在AngularJS ng-repeat中使用2个数组的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45958049/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com