Esse é o erro:
Uncaught TypeError: Cannot read property '0' of undefined
Bem o que passa é seguinte:
Faço uma busca em um WS. No retorno dessa busca, eu monto um html e jogo na minha view (cshtml). Bem, isso funciona.
Aí fiz uns filtros para buscar dentro da minha session, essa informações. Digamos que na minha session, eu tenho 29 Hotéis. Aí, pelo filtro de nome do hotel(um TextBox) eu seleciono um Hotel (Há um auto complete, que tá funcionando). Seleciono o hotel. No OnBlur
do textbox
, eu chamo uma função Jquery para carregar o hotel escolhido no textbox.
Ela carrega e nesse momento, eu pego o mesmo html que funciona na primeira carregada, dá esse erro. Eu já não sei mais o que fazer. Os código das funções que carregam o html são grandes, por isso não os postei, mas posso fazê-lo, se quiserem.
Meu searchResult que dá erro na busca
[HttpPost]
public JsonResult FiltroGeral(string[] refeicoes, string hotel, string[] categoria)
{
OfferV2[] pesquisaHotel = ((OfferV2[])SessaoUtil.Recuperar("PegaHotelPacote"));
List<object> searchResult = new List<object>();
if (refeicoes != null)
{
pesquisaHotel = pesquisaHotel.Where(x => refeicoes.Contains(x.CategoryId)).ToArray();
}
if (hotel != "")
{
pesquisaHotel = pesquisaHotel.Where(x => hotel.Contains(x.ProductName)).ToArray();
}
if (categoria != null)
{
pesquisaHotel = pesquisaHotel.Where(x => categoria.Contains(x.CategoryId)).ToArray();
}
searchResult.Add(pesquisaHotel);
return Json(new { searchResult }, JsonRequestBehavior.AllowGet);
}
Esse é minha jquery
function FiltroGeral() {
var Refeicoes = [];
var Hotel = [];
var Categoria = [];
var str;
var filtro;
var cont = 1;
var count = 1;
var camas = [];
var strHotel;
var strCategoria;
var valor = 0;
var menorValor = 0;
var parcelas;
var qQuartos;
dados = []
for (var i = 0; i < filtroPesquisa.chkcategoria.length; i++) {
if (filtroPesquisa.chkcategoria[i].checked) {
Categoria.push(filtroPesquisa.chkcategoria[i].value);
}
}
for (var i = 0; i < filtroPesquisa.chkrefeicao.length; i++) {
if (filtroPesquisa.chkrefeicao[i].checked) {
Refeicoes.push(filtroPesquisa.chkrefeicao[i].value);
}
}
$.ajax({
url: '/Hotel/FiltroGeral',
dataType: "json",
contentType: "application/json; charset=utf-8",
type: "POST",
data: JSON.stringify({ refeicoes: Refeicoes, hotel: $("#txtNomeHotel").val(), categoria: Categoria, Min: $("#ValorMin").val().replace(".", "").replace(",00", ""), Max: $("#ValorMax").val().replace(".", "").replace(",00", "") }),
success: function (data) {
$(data.searchResult).each(function () {
alert(ProductName);
//menorValor = this.SubOfferGroups[0].AnswerOffersList[0].SalePrice.Value;
//$(this.SubOfferGroups).each(function () {
// $(this.AnswerOffersList).each(function () {
// menorValor = Math.min(this.SalePrice.DefaultValue, this.SalePrice.DefaultValue);
// });
//});
if ($('#ValorHotel').val() != 0) {
menorValor = menorValor.toFixed(2) / $('#ValorHotel').val();
parcelas = $('#ValorHotel').val() + ' x'
}
str += '<div class="conteudo"> ';//Div inicial geral, fechar após tudo
str += '<div class="grid_11 margin-left-clear">';
str += '<div>';
str += '<h1>';
str += this.ProductName;
str += ' </h1>';
str += '<div class="valor">' + parcelas + ' ' + menorValor.toFixed(2) + '</div>'; // Inserir o valor com o parcelamento aqui
str += '<p>' + this.ShortDescription + '</p>';
str += '</div>';
str += '</div>';
str += '<div class="grid_8 margin-right-clear">';
str += '<div class="img-detalhes-hotel">';
str += '<img src="' + this.ImageList[0].URL + '" width="290" height="178" />';
str += '</div>';
str += '</div>';
str += '<div class="grid_19 row margin-bottom-10">';
str += '<div class="tab-detalhes-produto">';
str += '<a href="#fotos-0' + cont + '">Fotos</a>';
str += '</div>';
str += '<div class="tab-detalhes-produto">';
str += '<a href="#mapa-0' + cont + '">Mapa</a>';
str += '</div>';
str += '<div class="tab-detalhes-produto">';
str += '<a href="#servicos-0' + cont + '">Servicos</a>';
str += '</div>';
str += '<div class="tab-detalhes-produto">';
str += '<a href="#selecionar-quartos-0' + cont + '">Selecionar apartamento</a>';
str += '</div>';
str += '</div>';
str += '<div id="fotos-0' + cont + '" class="grid_19 fotos">';
str += '<div class="css3slider">';
if (this.ImageList.length > 0) {
$(this.ImageList).each(function () {
str += ' <input type="radio" name="slide_switch" id="' + cont + 'id' + count + '" checked="checked" />';
str += ' <label for="' + cont + 'id' + count + '">';
str += ' <img src="' + this.URL + '" />';
str += ' </label>';
str += ' <img src="' + this.URL + '" width="390" height="262" />';
count++;
});
}
str += '</div>';
str += '</div>';
str += '<div id="mapa-0' + cont + '" class="grid_19 mapa-localizacao-hotel">';
str += '<div class="map-canvas" data-opt=' + ' {"txtLatitude":' + this.Latitude + ',"txtLongitude":' + this.Longitude + '}' + ' style="display: block;width: 750px;height: 300px;"></div>';
str += '</div>';
str += '<div id="servicos-0' + cont + '" class="grid_19 servicos-hotel">';
str += '<p>' + this.Description + '</p>';
str += '</div>';
str += '<div id="selecionar-quartos-0' + cont + '" class="grid_19 selecionar-quartos">';
str += '<div class="grid_18 margin-left-15">';
str += '<h1>Selecione seus quartos de acordo com sua preferência</h1>';
$(this.SubOfferGroups).each(function () {
$(this.AnswerOffersList).each(function () {
valor = this.SalePrice.Value;
if (valor == "") {
valor = 0;
}
if ($('#ValorHotel').val() != 0) {
valor = valor.toFixed(2) / $('#ValorHotel').val();
}
str += '<div class="display-table border-bottom-cinza">';
str += '<div class="display-table">';
str += '<div class="grid_8">';
str += '<div class="valor">';
str += '<input type="checkbox" value="1" />';
str += this.ProductName + ' ' + parcelas + ' ' + valor.toFixed(2);
str += '</div>';
str += '</div>';
str += '<div class="grid_5">';
str += '<select class="select-group">';
str += '<option>Qtd. quartos</option>';
for (var i = 1; i < $("#Quartos").val() + 1; i++) {
if (i == 1)
str += '<option>' + i + ' quarto</option>';
else
str += '<option>' + i + ' quartos</option>';
if (i == $("#Quartos").val())
break;
}
str += '</select>';
str += '</div>';
str += '<div class="grid_4 selecionar-quartos-adicionais">';
str += '<a href="#dados-adicionais-quarto-0' + cont + '">+ informações</a>';
str += '</div>';
str += '</div>';
str += '<div id="dados-adicionais-quarto-0' + cont + '" class="dados-adicionais-quarto">';
str += '<div class="grid_11">';
str += '<table class="table table-bordered table-hover">';
str += '<thead>';
str += '<tr>';
str += '<td>Pessoas</td>';
str += '<td>Data</td>';
str += '<td>Preço</td>';
str += '</tr>';
str += '</thead>';
var adt = $('#txtAdulto').val();
var cri = $('#txtCrianca').val();
str += '<tbody>';
str += '<tr>';
str += '<td>' + (adt > 0 ? adt + ' Adulto(s)' : "") + ' ' + (cri > 0 ? cri + ' Criança(s)' : "") + '</td>';
str += '<td>' + '' + '</td>';
str += '<td>' + this.SalePrice.Value.toFixed(2) + '</td>';
str += '</tr>';
str += '</tbody>';
str += '</table>';
str += '</div>';
str += '<div class="grid_4">';
str += '<p>aqui será inserido o texto referente a serviços inclusos e politica de cancelamento</p>';
str += '</div>';
str += '</div>';
str += '</div>';
});
});
str += '</div>';
str += '</div>';
str += '</div>';
dados.push(str);
cont++;
str = "";
$("#Pagination").pagination(dados.length, {
items_per_page: 5,
num_display_entries: 1,
num_edge_entries: 1,
callback: pageselectCallback
});
});
},
error: function (error) {
alert("erro");
}
});
}
this
, então o erro seriaCannot read property 'ImageList' of undefined
... a não ser que ele tenha algo do tipothis[0]
, ai sim poderia ser.