【发布时间】:2016-10-21 14:52:26
【问题描述】:
我是新的 ionic,我关心的是显示我的数据列表的详细信息。我可以显示我的 JSON 的所有元素,但我不能提供详细信息。我的函数“GetPromo”把我变成了“null”。如何在 JSON 中获取元素“Hotel”的“id”?你可以帮帮我吗 ?谢谢
var app = angular.module('hotelsApp.controllers', [])
// My factory
app.factory("PromoService", function(){
var promos = [
{
"Hotel":{
"id":"52",
"typeEtablissement":"HOTEL",
"nomHotel":"AUBERGE DES ILES",
"email":"auberge@ghaima.ci",
"siteWeb":null,
"situationGeo":"Assinie",
"nombreChambre":"12",
"commune_id":"21",
"standing_id":"4",
"prixChambreMin":"5000",
"prixChambreMax":"15000",
"tarif":"5 000 \/ 15 000",
"description":"L'auberge des \u00eeles est un lieu paisible et reposant situ\u00e9 \u00e0 Assinie. Un cadre tout aussi propice \u00e0 l'\u00e9vasion et au loisir, vous accueille pour des s\u00e9jours \u00e0 court moyen et long terme.",
"typePaiement":"",
"autreinfo":"",
"logo":"\/img\/hotels\/52\/logo.jpg",
},
"Commune":{
"id":"21",
"libelle":"Assinie"
},
"Standing":{
"id":"4",
"nbEtoiles":"2",
"libelle":"2 Etoiles"
},
"Service":[
{
"id":"6",
"libelle":"Bar",
"Servicehotel":{
"id":"1360",
"hotel_id":"52",
"service_id":"6"
}
}
]
}
];
return {
GetPromos: function(){
return promos;
},
GetPromo: function(promoId){
for(var j = 0; j < promos.length; j++) {
if (promos[j].id === parseInt(promoId)) {
return promos[j];
}
}
return null;
}
}
});
// My controllers
app.controller('PromosCtrl', function($scope, PromoService) {
$scope.promos = PromoService.GetPromos();
});
app.controller('PromoCtrl', function($scope, $stateParams, PromoService) {
promoId = $stateParams.promoId;
$scope.promos[Hotel] = PromoService.GetPromo(promoId);
});
【问题讨论】:
标签: json ionic-framework factory