我设计了一个酒店选择器区块,客户可以根据当天所有可用的酒店和该位置选择酒店,我已成功获取目的地和日期的所有可用酒店,并将所有酒店显示为col-md-4的单个网格(框)。但我想要的是给客户一个按钮,根据酒店类型(一个数字星值)对酒店进行分类,并将结果显示为排序。
我的ajax代码来取酒店:
function hotel_selector(id,location,date){
jQuery(document).ready(function($){
$('.loader').show();
$('#hotel_details').empty();
$.ajax({
type:'post',
url:'admin/new_admin/hotel_selector.php',
data: 'location='+ location +'&date='+date,
success: function(value){
var value1 = value;
value1.sort(function(a, b) {
return parseFloat(a.hotel_type) - parseFloat(b.hotel_type);
});
var data = JSON.parse(value1);
alert(value1);
$('#show_hotel').modal('show');
var hotel_at = location.substr(0,1).toUpperCase()+location.substr(1);
$("#hotel_at").html(hotel_at);
$("#hotel_on").html(date);
var a = 0;
var b = 0;
var c = 0;
var status = 0;
var html='';
for(a=0;a<data.length;a++){
html += '<div class="col-md-4 col-xs-6">';
html += '<div class="panel panel-primary">';
html += '<div class="panel-heading">';
html += data[a].hotel_name;
html += '</div>';
html += '<div class="panel-body" style="height: 350px;">';
html += '<div class="col-md-12">';
html += '<img src="hotel_images/thumb/'+data[a].hotel_img+'" class="img-responsive img-thumbnail"/>';
html += '</div>';
html += '<div class="col-md-12 padding-top-10 text-smaller">';
var hotel_id = data[a].hotel_id;
for(b=0;b<data[a].rooms.length;b++)
{
if(data[a].rooms[b].hotel_id == hotel_id){
var roomtype_id = data[a].rooms[b].roomtype_id;
for(c=0;c<data[a].rooms[b].inventory.length;c++){
if(data[a].rooms[b].inventory[c].hotel_id == hotel_id && data[a].rooms[b].inventory[c].roomtype_id == roomtype_id && data[a].rooms[b].inventory[c].cost != 0 && data[a].rooms[b].inventory[c].available_rooms != 0){
html += '<label class="left"><input type="radio" autocomplete="off" value="'+data[a].rooms[b].roomtype_id+'" name="room_type'+id+'">'+data[a].rooms[b].type_name+' (Rs. '+data[a].rooms[b].inventory[c].cost+') </label><br />';
var status = 1;
}
else{
html += '<label class="left"><input type="radio" autocomplete="off" value="'+data[a].rooms[b].roomtype_id+'" name="room_type'+id+'" disabled>'+data[a].rooms[b].type_name+' <font size="0.1px" class="text-danger">(sold)</font> </label><br />';
var status = 1;
}
}
}
}
html += '</div>';
html += '</div>';
html += '<div class="panel-footer">';
if(c > 0){
html += '<a href="#" class="btn btn-success btn-block" onclick="changeHotel(\''+id+'\',\''+data[a].hotel_id+'\', \''+data[a].hotel_name+'\', \''+data[a].hotel_img+'\', \''+data[a].hotel_location+'\', \''+data[a].hotel_type+'\')" data-dismiss="modal" aria-hidden="true">Add</a>';
}
else{
html += '<a href="#" class="btn btn-success btn-block" disabled>Add</a>';
}
html += '</div>';
html += '</div>';
html += '</div>';
}
$('#hotel_details').append(html);
$(".loader").fadeOut("slow");
}
});
});
}
我得到的json回复是:
[{"hotel_id":"1","hotel_name":"White Coral","hotel_location":"portblair","hotel_type":"3","hotel_description":"<div id=\"TA_cdsratingsonlynarrow624\" class=\"TA_cdsratingsonlynarrow\">\r\n<ul id=\"muuhoTm4F\" class=\"TA_links xPatAm\">\r\n<li id=\"MjbI7weT8\" class=\"VDC6wQG\">\r\n<a target=\"_blank\" href=\"https:\/\/www.tripadvisor.com\/\"><img src=\"https:\/\/www.tripadvisor.com\/img\/cdsi\/img2\/branding\/tripadvisor_logo_transp_340x80-18034-2.png\" alt=\"TripAdvisor\"\/><\/a>\r\n<\/li>\r\n<\/ul>\r\n<\/div>\r\n<script src=\"https:\/\/www.tripadvisor.com\/WidgetEmbed-cdsratingsonlynarrow?amp;locationId=7112033&border=false&uniq=624&lang=en_US&display_version=2\"><\/script>\r\n","hotel_img":"White Coral.jpg","visibility":"visible","rooms":[{"roomtype_id":"1","hotel_id":"1","type_name":"Standard","meal_plan":"MAP","description":"Bed: Queen Occupancy: 2 Persons Size: 180 Sqft View: Lakeview\/Mountain View, Ensuit Bathroom: Cable T.V: Coffee\/Tea maker: Free Internet: Breakfast Included: Balcony: Extra Matress: Room Service: Hot Running Water: Glass Window: ","img":"Standard.jpg","inventory":[{"inventory_id":"175","hotel_id":"1","roomtype_id":"1","capacity_id":"0","date_id":"211","cost":"2600","available_rooms":"10","booked_rooms":"0","blocked_rooms":"0","meal":"400","em":"1000","wem":"800"}]}]},{"hotel_id":"2","hotel_name":"Hotel Velocity","hotel_location":"portblair","hotel_type":"2","hotel_description":"<div id=\"TA_cdsratingsonlynarrow562\" class=\"TA_cdsratingsonlynarrow\">\r\n<ul id=\"CKNqwJp\" class=\"TA_links JQijv3tc\">\r\n<li id=\"gKt7XdWVdd4J\" class=\"DqSO1ad\">\r\n<a target=\"_blank\" href=\"https:\/\/www.tripadvisor.in\/\"><img src=\"https:\/\/www.tripadvisor.in\/img\/cdsi\/img2\/branding\/tripadvisor_logo_transp_340x80-18034-2.png\" alt=\"TripAdvisor\"\/><\/a>\r\n<\/li>\r\n<\/ul>\r\n<\/div>\r\n<script src=\"https:\/\/www.tripadvisor.com\/WidgetEmbed-cdsratingsonlynarrow?amp;locationId=5778821&border=false&uniq=562&lang=en_IN&display_version=2%22\"><\/script>","hotel_img":"Hotel Velocity.jpg","visibility":"visible","rooms":[{"roomtype_id":"2","hotel_id":"2","type_name":"Standard","meal_plan":"CP","description":"Room size 13 \u2013 19,5 m2, One or two beds 90 \u2013 180 cm, Bathroom with shower or bath ","img":"Standard.jpg","inventory":[{"inventory_id":"1371","hotel_id":"2","roomtype_id":"2","capacity_id":"0","date_id":"211","cost":"2000","available_rooms":"5","booked_rooms":"0","blocked_rooms":"0","meal":"350","em":"800","wem":"600"}]},{"roomtype_id":"3","hotel_id":"2","type_name":"Deluxe","meal_plan":"CP","description":"Room size 17,5 \u2013 19,5 m2, One or two beds 90-180 cm, Complimentary bottled water, Extra pillows, Bed cover and decorative pillows, Bathroom with shower or bath Designer bathroom amenities","img":"Deluxe.jpg","inventory":[{"inventory_id":"1969","hotel_id":"2","roomtype_id":"3","capacity_id":"0","date_id":"211","cost":"2200","available_rooms":"5","booked_rooms":"0","blocked_rooms":"0","meal":"350","em":"800","wem":"600"}]},{"roomtype_id":"4","hotel_id":"2","type_name":"Family(3 bed)","meal_plan":"CP","description":"Room size 37 \u2013 39 m2, One bed 200 cm, Bathrobe and Slippers,Coffee and tea making facilities, Folding sofa, Designer bathroom amenities","img":"Family(3 bed).jpg","inventory":[{"inventory_id":"2567","hotel_id":"2","roomtype_id":"4","capacity_id":"0","date_id":"211","cost":"3000","available_rooms":"2","booked_rooms":"0","blocked_rooms":"0","meal":"350","em":"800","wem":"600"}]}]},{"hotel_id":"3","hotel_name":"Suncity Resort ","hotel_location":"portblair","hotel_type":"4","hotel_description":"<div id=\"TA_cdsratingsonlynarrow61\" class=\"TA_cdsratingsonlynarrow\">\r\n<ul id=\"i44YsiWR2l\" class=\"TA_links I6Yn53nu3q\">\r\n<li id=\"IXnbV3\" class=\"Ced4Dj6K\">\r\n<a target=\"_blank\" href=\"https:\/\/www.tripadvisor.in\/\"><img src=\"https:\/\/www.tripadvisor.in\/img\/cdsi\/img2\/branding\/tripadvisor_logo_transp_340x80-18034-2.png\" alt=\"TripAdvisor\"\/><\/a>\r\n<\/li>\r\n<\/ul>\r\n<\/div>\r\n<script src=\"https:\/\/www.tripadvisor.com\/WidgetEmbed-cdsratingsonlynarrow?amp;locationId=1892754&border=false&uniq=61&lang=en_IN&display_version=2\"><\/script>","hotel_img":"Suncity Resort .jpg","visibility":"visible","rooms":[{"roomtype_id":"5","hotel_id":"3","type_name":"Deluxe","meal_plan":"CP","description":" ","img":"","inventory":[{"inventory_id":"3165","hotel_id":"3","roomtype_id":"5","capacity_id":"0","date_id":"211","cost":"6000","available_rooms":"5","booked_rooms":"0","blocked_rooms":"0","meal":"600","em":"2000","wem":"1500"}]}]},{"hotel_id":"4","hotel_name":"Hotel Marine View","hotel_location":"portblair","hotel_type":"2","hotel_description":"<div id=\"TA_cdsratingsonlynarrow694\" class=\"TA_cdsratingsonlynarrow\">\r\n<ul id=\"zIqNmRREGZ3w\" class=\"TA_links ec6UrDUX\">\r\n<li id=\"kdZW1TAoh\" class=\"UnfkCBw5I\">\r\n<a target=\"_blank\" href=\"https:\/\/www.tripadvisor.in\/\"><img src=\"https:\/\/www.tripadvisor.in\/img\/cdsi\/img2\/branding\/tripadvisor_logo_transp_340x80-18034-2.png\" alt=\"TripAdvisor\"\/><\/a>\r\n<\/li>\r\n<\/ul>\r\n<\/div>\r\n<script src=\"https:\/\/www.tripadvisor.com\/WidgetEmbed-cdsratingsonlynarrow?amp;locationId=1734210&border=false&uniq=694&lang=en_IN&display_version=2\"><\/script>","hotel_img":"Hotel Marine View.jpg","visibility":"visible","rooms":[{"roomtype_id":"6","hotel_id":"4","type_name":"Standard","meal_plan":"CP","description":" ","img":"","inventory":[{"inventory_id":"4357","hotel_id":"4","roomtype_id":"6","capacity_id":"0","date_id":"211","cost":"2000","available_rooms":"5","booked_rooms":"0","blocked_rooms":"0","meal":"400","em":"800","wem":"600"}]},{"roomtype_id":"7","hotel_id":"4","type_name":"Standard (triple)","meal_plan":"CP","description":" ","img":"","inventory":[{"inventory_id":"4953","hotel_id":"4","roomtype_id":"7","capacity_id":"0","date_id":"211","cost":"2700","available_rooms":"3","booked_rooms":"0","blocked_rooms":"0","meal":"400","em":"800","wem":"600"}]}]},{"hotel_id":"5","hotel_name":"Chaukhat (Bed & Breakfast)","hotel_location":"portblair","hotel_type":"3","hotel_description":"<div id=\"TA_cdsratingsonlynarrow956\" class=\"TA_cdsratingsonlynarrow\">\r\n<ul id=\"UUYd3fadT51V\" class=\"TA_links FL5iBx9W\">\r\n<li id=\"m3G7WFWAM\" class=\"A76s7CWQQpE\">\r\n<a target=\"_blank\" href=\"https:\/\/www.tripadvisor.in\/\"><img src=\"https:\/\/www.tripadvisor.in\/img\/cdsi\/img2\/branding\/tripadvisor_logo_transp_340x80-18034-2.png\" alt=\"TripAdvisor\"\/><\/a>\r\n<\/li>\r\n<\/ul>\r\n<\/div>\r\n<script src=\"https:\/\/www.tripadvisor.com\/WidgetEmbed-cdsratingsonlynarrow?amp;locationId=4893817&border=false&uniq=956&lang=en_IN&display_version=2\"><\/script>\r\n","hotel_img":"Chaukhat (Bed & Breakfast).jpg","visibility":"visible","rooms":[{"roomtype_id":"8","hotel_id":"5","type_name":"Standard","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"5549","hotel_id":"5","roomtype_id":"8","capacity_id":"0","date_id":"211","cost":"2800","available_rooms":"6","booked_rooms":"0","blocked_rooms":"0","meal":"400","em":"1000","wem":"800"}]}]},{"hotel_id":"6","hotel_name":"Peerless Sarovar Portico","hotel_location":"portblair","hotel_type":"4","hotel_description":"<div id=\"TA_cdsratingsonlynarrow695\" class=\"TA_cdsratingsonlynarrow\">\r\n<ul id=\"FdDyiFmdU5\" class=\"TA_links aa6rTQw\">\r\n<li id=\"wNOlhi\" class=\"X7AjISr\">\r\n<a target=\"_blank\" href=\"https:\/\/www.tripadvisor.in\/\"><img src=\"https:\/\/www.tripadvisor.in\/img\/cdsi\/img2\/branding\/tripadvisor_logo_transp_340x80-18034-2.png\" alt=\"TripAdvisor\"\/><\/a>\r\n<\/li>\r\n<\/ul>\r\n<\/div>\r\n<script src=\"https:\/\/www.tripadvisor.com\/WidgetEmbed-cdsratingsonlynarrow?amp;locationId=499988&border=false&uniq=695&lang=en_IN&display_version=2\"><\/script>","hotel_img":"Peerless Sarovar Portico.jpg","visibility":"visible","rooms":[{"roomtype_id":"9","hotel_id":"6","type_name":"Deluxe","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"6145","hotel_id":"6","roomtype_id":"9","capacity_id":"0","date_id":"211","cost":"6500","available_rooms":"8","booked_rooms":"0","blocked_rooms":"0","meal":"600","em":"2000","wem":"1500"}]},{"roomtype_id":"125","hotel_id":"6","type_name":"Sea View","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"11957","hotel_id":"6","roomtype_id":"125","capacity_id":"0","date_id":"211","cost":"11000","available_rooms":"0","booked_rooms":"0","blocked_rooms":"0","meal":"600","em":"2000","wem":"1500"}]},{"roomtype_id":"126","hotel_id":"6","type_name":"Cottage","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"12548","hotel_id":"6","roomtype_id":"126","capacity_id":"0","date_id":"211","cost":"12000","available_rooms":"0","booked_rooms":"0","blocked_rooms":"0","meal":"600","em":"2000","wem":"1500"}]}]},{"hotel_id":"7","hotel_name":"Hotel Ritz","hotel_location":"portblair","hotel_type":"1","hotel_description":"No Reviews\r\n","hotel_img":"Hotel Ritz.jpg","visibility":"visible","rooms":[{"roomtype_id":"10","hotel_id":"7","type_name":"Standard","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"6741","hotel_id":"7","roomtype_id":"10","capacity_id":"0","date_id":"211","cost":"1600","available_rooms":"8","booked_rooms":"0","blocked_rooms":"0","meal":"350","em":"600","wem":"400"}]},{"roomtype_id":"11","hotel_id":"7","type_name":"Four Bed","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"7336","hotel_id":"7","roomtype_id":"11","capacity_id":"0","date_id":"211","cost":"3000","available_rooms":"3","booked_rooms":"0","blocked_rooms":"0","meal":"350","em":"600","wem":"400"}]}]},{"hotel_id":"8","hotel_name":"PEARL HARBOUR","hotel_location":"portblair","hotel_type":"0","hotel_description":"<div id=\"TA_linkingWidgetRedesign54\" class=\"TA_linkingWidgetRedesign\">\r\n<ul id=\"xOGGOVauUr\" class=\"TA_links 3BnQMXk\">\r\n<li id=\"P2YAQRO9rJ\" class=\"NJcJJGHws\">\r\n<a target=\"_blank\" href=\"https:\/\/www.tripadvisor.in\/\"><img src=\"https:\/\/www.tripadvisor.in\/img\/cdsi\/partner\/tripadvisor_logo_115x18-15079-2.gif\" alt=\"TripAdvisor\"\/><\/a>\r\n<\/li>\r\n<\/ul>\r\n<\/div>\r\n<script src=\"https:\/\/www.tripadvisor.com\/WidgetEmbed-linkingWidgetRedesign?amp;locationId=6957605&border=false&uniq=54&lang=en_IN&display_version=2\"><\/script>","hotel_img":"PEARL HARBOUR.jpg","visibility":"visible","rooms":[{"roomtype_id":"12","hotel_id":"8","type_name":"Standard Ac","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"7931","hotel_id":"8","roomtype_id":"12","capacity_id":"0","date_id":"211","cost":"1500","available_rooms":"10","booked_rooms":"0","blocked_rooms":"0","meal":"300","em":"600","wem":"400"}]},{"roomtype_id":"13","hotel_id":"8","type_name":"Triple Ac","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"8526","hotel_id":"8","roomtype_id":"13","capacity_id":"0","date_id":"211","cost":"2000","available_rooms":"5","booked_rooms":"0","blocked_rooms":"0","meal":"300","em":"600","wem":"400"}]},{"roomtype_id":"14","hotel_id":"8","type_name":"Standard Non Ac","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"9121","hotel_id":"8","roomtype_id":"14","capacity_id":"0","date_id":"211","cost":"1200","available_rooms":"5","booked_rooms":"0","blocked_rooms":"0","meal":"300","em":"500","wem":"400"}]},{"roomtype_id":"15","hotel_id":"8","type_name":"Triple Non Ac","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"9716","hotel_id":"8","roomtype_id":"15","capacity_id":"0","date_id":"211","cost":"1600","available_rooms":"3","booked_rooms":"0","blocked_rooms":"0","meal":"300","em":"500","wem":"400"}]}]},{"hotel_id":"9","hotel_name":"Hotel Abhishekh","hotel_location":"portblair","hotel_type":"1","hotel_description":"No Reviews","hotel_img":"Hotel Abhishekh.jpg","visibility":"visible","rooms":[{"roomtype_id":"16","hotel_id":"9","type_name":"Standard","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"10311","hotel_id":"9","roomtype_id":"16","capacity_id":"0","date_id":"211","cost":"1500","available_rooms":"8","booked_rooms":"0","blocked_rooms":"0","meal":"350","em":"600","wem":"500"}]},{"roomtype_id":"17","hotel_id":"9","type_name":"Deluxe","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"10906","hotel_id":"9","roomtype_id":"17","capacity_id":"0","date_id":"211","cost":"1800","available_rooms":"5","booked_rooms":"0","blocked_rooms":"0","meal":"350","em":"600","wem":"500"}]}]},{"hotel_id":"10","hotel_name":"HOTEL PHOENIX","hotel_location":"portblair","hotel_type":"0","hotel_description":"No Reviews","hotel_img":"HOTEL PHOENIX.jpg","visibility":"visible","rooms":[{"roomtype_id":"18","hotel_id":"10","type_name":"Standard Ac ","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"13139","hotel_id":"10","roomtype_id":"18","capacity_id":"0","date_id":"211","cost":"1300","available_rooms":"10","booked_rooms":"0","blocked_rooms":"0","meal":"200","em":"500","wem":"400"}]},{"roomtype_id":"19","hotel_id":"10","type_name":"Standard Non Ac","meal_plan":"EP","description":"","img":"","inventory":[{"inventory_id":"13730","hotel_id":"10","roomtype_id":"19","capacity_id":"0","date_id":"211","cost":"1000","available_rooms":"10","booked_rooms":"0","blocked_rooms":"0","meal":"200","em":"500","wem":"400"}]}]},{"hotel_id":"11","hotel_name":"HOTEL ACC","hotel_location":"portblair","hotel_type":"0","hotel_description":"No Reviews","hotel_img":"HOTEL ACC.jpg","visibility":"visible","rooms":[{"roomtype_id":"20","hotel_id":"11","type_name":"Standard Ac","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"14321","hotel_id":"11","roomtype_id":"20","capacity_id":"0","date_id":"211","cost":"1200","available_rooms":"10","booked_rooms":"0","blocked_rooms":"0","meal":"200","em":"400","wem":"300"}]},{"roomtype_id":"21","hotel_id":"11","type_name":"Standard Non Ac","meal_plan":"EP","description":"","img":"","inventory":[{"inventory_id":"14912","hotel_id":"11","roomtype_id":"21","capacity_id":"0","date_id":"211","cost":"1000","available_rooms":"8","booked_rooms":"0","blocked_rooms":"0","meal":"200","em":"400","wem":"300"}]}]},{"hotel_id":"12","hotel_name":"Anugama Resort","hotel_location":"portblair","hotel_type":"2","hotel_description":"<div id=\"TA_cdsratingsonlynarrow458\" class=\"TA_cdsratingsonlynarrow\">\r\n<ul id=\"UUsjVs\" class=\"TA_links Xq2vXyNK\">\r\n<li id=\"cxMQyI58S\" class=\"AvxBWOS7RP\">\r\n<a target=\"_blank\" href=\"https:\/\/www.tripadvisor.in\/\"><img src=\"https:\/\/www.tripadvisor.in\/img\/cdsi\/img2\/branding\/tripadvisor_logo_transp_340x80-18034-2.png\" alt=\"TripAdvisor\"\/><\/a>\r\n<\/li>\r\n<\/ul>\r\n<\/div>\r\n<script src=\"https:\/\/www.tripadvisor.com\/WidgetEmbed-cdsratingsonlynarrow?amp;locationId=1058876&border=false&uniq=458&lang=en_IN&display_version=2\"><\/script>","hotel_img":"Anugama Resort.jpg","visibility":"visible","rooms":[{"roomtype_id":"22","hotel_id":"12","type_name":"Standard","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"15503","hotel_id":"12","roomtype_id":"22","capacity_id":"0","date_id":"211","cost":"3500","available_rooms":"8","booked_rooms":"0","blocked_rooms":"0","meal":"450","em":"1000","wem":"800"}]}]},{"hotel_id":"13","hotel_name":"Coastal Breeze","hotel_location":"portblair","hotel_type":"1","hotel_description":"No Reviews","hotel_img":"Coastal Breeze.jpg","visibility":"visible","rooms":[{"roomtype_id":"26","hotel_id":"13","type_name":"Standard","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"16094","hotel_id":"13","roomtype_id":"26","capacity_id":"0","date_id":"211","cost":"2500","available_rooms":"6","booked_rooms":"0","blocked_rooms":"0","meal":"350","em":"800","wem":"600"}]}]},{"hotel_id":"14","hotel_name":" WESTERN PARK","hotel_location":"portblair","hotel_type":"2","hotel_description":"<div id=\"TA_cdsratingsonlynarrow340\" class=\"TA_cdsratingsonlynarrow\">\r\n<ul id=\"BbgM6A\" class=\"TA_links DjgpIPSoV\">\r\n<li id=\"362vxWW\" class=\"UDotIithe\">\r\n<a target=\"_blank\" href=\"https:\/\/www.tripadvisor.in\/\"><img src=\"https:\/\/www.tripadvisor.in\/img\/cdsi\/img2\/branding\/tripadvisor_logo_transp_340x80-18034-2.png\" alt=\"TripAdvisor\"\/><\/a>\r\n<\/li>\r\n<\/ul>\r\n<\/div>\r\n<script src=\"https:\/\/www.tripadvisor.com\/WidgetEmbed-cdsratingsonlynarrow?amp;locationId=8117352&border=false&uniq=340&lang=en_IN&display_version=2\"><\/script>","hotel_img":" WESTERN PARK.jpg","visibility":"visible","rooms":[{"roomtype_id":"23","hotel_id":"14","type_name":"Standard","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"16685","hotel_id":"14","roomtype_id":"23","capacity_id":"0","date_id":"211","cost":"2000","available_rooms":"10","booked_rooms":"0","blocked_rooms":"0","meal":"350","em":"800","wem":"600"}]},{"roomtype_id":"24","hotel_id":"14","type_name":"Deluxe","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"17276","hotel_id":"14","roomtype_id":"24","capacity_id":"0","date_id":"211","cost":"2500","available_rooms":"6","booked_rooms":"0","blocked_rooms":"0","meal":"350","em":"800","wem":"600"}]},{"roomtype_id":"25","hotel_id":"14","type_name":"Family(3 bed)","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"17867","hotel_id":"14","roomtype_id":"25","capacity_id":"0","date_id":"211","cost":"3000","available_rooms":"5","booked_rooms":"0","blocked_rooms":"0","meal":"350","em":"800","wem":"600"}]}]},{"hotel_id":"17","hotel_name":"Serenity Homes","hotel_location":"portblair","hotel_type":"0","hotel_description":"No Reviews","hotel_img":"Serenity Homes.jpg","visibility":"visible","rooms":[{"roomtype_id":"33","hotel_id":"17","type_name":"Standard Non Ac","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"18458","hotel_id":"17","roomtype_id":"33","capacity_id":"0","date_id":"211","cost":"1000","available_rooms":"5","booked_rooms":"0","blocked_rooms":"0","meal":"200","em":"500","wem":"400"}]},{"roomtype_id":"34","hotel_id":"17","type_name":"Standard Ac","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"19049","hotel_id":"17","roomtype_id":"34","capacity_id":"0","date_id":"211","cost":"1200","available_rooms":"5","booked_rooms":"0","blocked_rooms":"0","meal":"200","em":"500","wem":"400"}]},{"roomtype_id":"35","hotel_id":"17","type_name":"Standard (triple) Ac","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"20161","hotel_id":"17","roomtype_id":"35","capacity_id":"0","date_id":"211","cost":"2000","available_rooms":"5","booked_rooms":"0","blocked_rooms":"0","meal":"200","em":"500","wem":"400"}]},{"roomtype_id":"36","hotel_id":"17","type_name":"Standard (triple) Non Ac","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"20822","hotel_id":"17","roomtype_id":"36","capacity_id":"0","date_id":"211","cost":"600","available_rooms":"5","booked_rooms":"0","blocked_rooms":"0","meal":"200","em":"500","wem":"400"}]},{"roomtype_id":"37","hotel_id":"17","type_name":"Four Bed Ac ","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"21413","hotel_id":"17","roomtype_id":"37","capacity_id":"0","date_id":"211","cost":"2200","available_rooms":"5","booked_rooms":"0","blocked_rooms":"0","meal":"200","em":"500","wem":"400"}]},{"roomtype_id":"38","hotel_id":"17","type_name":"Four Bed Non Ac ","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"22377","hotel_id":"17","roomtype_id":"38","capacity_id":"0","date_id":"211","cost":"1800","available_rooms":"5","booked_rooms":"0","blocked_rooms":"0","meal":"200","em":"500","wem":"400"}]}]},{"hotel_id":"24","hotel_name":"Hotel TSG Grand","hotel_location":"portblair","hotel_type":"3","hotel_description":"<div id=\"TA_cdsratingsonlynarrow963\" class=\"TA_cdsratingsonlynarrow\">\r\n<ul id=\"giG785\" class=\"TA_links CvC6mJd1q\">\r\n<li id=\"An5Cec\" class=\"h00MRh3\">\r\n<a target=\"_blank\" href=\"https:\/\/www.tripadvisor.in\/\"><img src=\"https:\/\/www.tripadvisor.in\/img\/cdsi\/img2\/branding\/tripadvisor_logo_transp_340x80-18034-2.png\" alt=\"TripAdvisor\"\/><\/a>\r\n<\/li>\r\n<\/ul>\r\n<\/div>\r\n<script src=\"https:\/\/www.tripadvisor.com\/WidgetEmbed-cdsratingsonlynarrow?amp;locationId=3740803&border=false&uniq=963&lang=en_IN&display_version=2\"><\/script>","hotel_img":"Hotel TSG Grand.jpg","visibility":"visible","rooms":[{"roomtype_id":"48","hotel_id":"24","type_name":"Standard","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"36196","hotel_id":"24","roomtype_id":"48","capacity_id":"0","date_id":"211","cost":"3200","available_rooms":"10","booked_rooms":"0","blocked_rooms":"0","meal":"450","em":"1500","wem":"1000"}]},{"roomtype_id":"49","hotel_id":"24","type_name":"Deluxe","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"36387","hotel_id":"24","roomtype_id":"49","capacity_id":"0","date_id":"211","cost":"3700","available_rooms":"10","booked_rooms":"0","blocked_rooms":"0","meal":"450","em":"1500","wem":"1000"}]}]},{"hotel_id":"25","hotel_name":"KAVITHA REGENT","hotel_location":"portblair","hotel_type":"2","hotel_description":"<div id=\"TA_cdsratingsonlynarrow882\" class=\"TA_cdsratingsonlynarrow\">\r\n<ul id=\"nmIiQMmWaq\" class=\"TA_links uO3X0oddyz\">\r\n<li id=\"g3Oo6H0\" class=\"j2kYdkcAppAo\">\r\n<a target=\"_blank\" href=\"https:\/\/www.tripadvisor.in\/\"><img src=\"https:\/\/www.tripadvisor.in\/img\/cdsi\/img2\/branding\/tripadvisor_logo_transp_340x80-18034-2.png\" alt=\"TripAdvisor\"\/><\/a>\r\n<\/li>\r\n<\/ul>\r\n<\/div>\r\n<script src=\"https:\/\/www.tripadvisor.com\/WidgetEmbed-cdsratingsonlynarrow?amp;locationId=7686880&border=false&uniq=882&lang=en_IN&display_version=2\"><\/script>","hotel_img":"KAVITHA REGENT.jpg","visibility":"visible","rooms":[{"roomtype_id":"61","hotel_id":"25","type_name":"Executive","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"39436","hotel_id":"25","roomtype_id":"61","capacity_id":"0","date_id":"211","cost":"2300","available_rooms":"8","booked_rooms":"0","blocked_rooms":"0","meal":"430","em":"1000","wem":"1000"}]},{"roomtype_id":"62","hotel_id":"25","type_name":"Classic","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"40084","hotel_id":"25","roomtype_id":"62","capacity_id":"0","date_id":"211","cost":"2800","available_rooms":"6","booked_rooms":"0","blocked_rooms":"0","meal":"430","em":"1000","wem":"1000"}]},{"roomtype_id":"63","hotel_id":"25","type_name":"Imperial","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"40732","hotel_id":"25","roomtype_id":"63","capacity_id":"0","date_id":"211","cost":"3800","available_rooms":"4","booked_rooms":"0","blocked_rooms":"0","meal":"430","em":"1000","wem":"1000"}]}]},{"hotel_id":"27","hotel_name":"Sun Sea Resort","hotel_location":"portblair","hotel_type":"3","hotel_description":"<div id=\"TA_cdsratingsonlynarrow663\" class=\"TA_cdsratingsonlynarrow\">\r\n<ul id=\"itxC38Xsb5aX\" class=\"TA_links k8x2ziyK\">\r\n<li id=\"BoxPi2\" class=\"adxrMMfpWL\">\r\n<a target=\"_blank\" href=\"https:\/\/www.tripadvisor.in\/\"><img src=\"https:\/\/www.tripadvisor.in\/img\/cdsi\/img2\/branding\/tripadvisor_logo_transp_340x80-18034-2.png\" alt=\"TripAdvisor\"\/><\/a>\r\n<\/li>\r\n<\/ul>\r\n<\/div>\r\n'<script src=\"https:\/\/www.tripadvisor.com\/WidgetEmbed-cdsratingsonlynarrow?amp;locationId=1157862&border=false&uniq=663&lang=en_IN&display_version=2\"><\/script>","hotel_img":"Sun Sea Resort.jpg","visibility":"visible","rooms":[{"roomtype_id":"58","hotel_id":"27","type_name":"Standard","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"41380","hotel_id":"27","roomtype_id":"58","capacity_id":"0","date_id":"211","cost":"3000","available_rooms":"8","booked_rooms":"0","blocked_rooms":"0","meal":"370","em":"1000","wem":"800"}]},{"roomtype_id":"59","hotel_id":"27","type_name":"Executive","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"42028","hotel_id":"27","roomtype_id":"59","capacity_id":"0","date_id":"211","cost":"3500","available_rooms":"6","booked_rooms":"0","blocked_rooms":"0","meal":"370","em":"1000","wem":"800"}]},{"roomtype_id":"60","hotel_id":"27","type_name":"Family(4 bed)","meal_plan":"CP","description":"","img":"","inventory":[{"inventory_id":"42676","hotel_id":"27","roomtype_id":"60","capacity_id":"0","date_id":"211","cost":"5600","available_rooms":"3","booked_rooms":"0","blocked_rooms":"0","meal":"370","em":"1000","wem":"800"}]}]}]
我想要的是一个按酒店开始排序的按钮(hotel_type)。
任何帮助都会被提前评价,而不是提前。
答案 0 :(得分:1)
data.sort(function(a,b){
if(a.hotel_type < b.hotel_type) return -1;
if(a.hotel_type > b.hotel_type) return 1;
return 0;
})