Reputation: 5534
I have a Jquery mobile Project with some pages into main, one of them has this structure:
@*Pagina componentes del documento*@
<div id="PagDocumentoComponentes" data-role="page" data-theme="a">
<div data-role="header" data-position="fixed">
<a id="BtnVolverPagComponentes" href="#" data-rel="back" data-icon="back">Volver</a>
<span id="PagDocumentoComponentesAdvertencia" style="color:red">Kit Incompleto</span>
<h3 id="PagDocumentoComponentesTitulo">Componentes del Kit</h3>
</div>
<div data-role="content">
<p>
<div data-role="collapsible-set" data-mini="true" data-inset="true" data-filter="true" id="ComponentesDocumentoDisponibles">
<div data-role="collapsible" data-theme="e">
<h2>No hay componentes</h2>
</div>
</div>
</p>
</div>
</div>
Collapsible set marked with id="ComponentesDocumentoDisponibles", is filled dynamically with this code:
function mostrarComponentes(tcLink) {
$.post(tcLink, function (dataComponentes) {
$('#ComponentesDocumentoDisponibles').children('.ui-collapsible').children('ul').remove('li',false);
$('#ComponentesDocumentoDisponibles').children('.ui-collapsible').remove();
// Se recorre cada item del kit que tiene componentes variables
}).error(function (dataError) {
alert('No se pudo caragr la información el kit (' + dataError + ')');
}).success(function (dataComponentes) {
var kitNode = ''
var ItemNode = '';
$(dataComponentes).each(function (object) {
var kit = $(this)[0];
var idComponente = kit.id;
kitNode += format('<div data-role="collapsible" data-max="1" id ="{0}" data-theme="e">', idComponente + "Collapsible");
kitNode += format(' <h2>{0}</h2>', kit.StrDescripcion);
kitNode += format(' <ul data-role="listview" data-inset="true" id="{0}">', idComponente);
// Se recorre cada item que compone el kit
$(kit.ItemsEnKit).each(function (object) {
var item = $(this)[0];
var iconoResta = '<image src="' + item.Image.toString() + '" class="ui-li-icon" style="width:22px;height:22px" />'
ItemNode = format('<li data-cantidad="{0}" data-icon="plus" id="{1}">', item.NumCantidadAsignada.toString().trim(), item.Id);
ItemNode += format(' <a href="#" onclick="modificarComponentes({0},{1});">{2} {3}</a>', quote(item.AccionDisminuir), quote(item.IdCantidad), iconoResta, item.StrDescripcion);
ItemNode += format(' <a href="#" onclick="modificarComponentes({0},{1});"></a>', quote(item.AccionAumentar), quote(item.IdCantidad));
ItemNode += format(' <span id="{0}" class="ui-li-count">{1}</span>', item.IdCantidad, item.NumCantidadAsignada);
ItemNode += format('</li>');
kitNode += ItemNode;
});
kitNode += format(' </ul>');
kitNode += format('</div>');
});
$('#ComponentesDocumentoDisponibles').html(kitNode);
$('#ComponentesDocumentoDisponibles').collapsible();
$('#ComponentesDocumentoDisponibles').find('div[data-role=collapsible]').collapsible();
$(dataComponentes).each(function (object) {
var kit = $(this)[0];
$("#" + kit.id + "Collapsible" ).collapsible();
try
{
$("#" + kit.id).listview();
} catch (e) {
alert(e.message);
}
});
});
//PagDocumentoComponentes
//ComponentesDocumentoDisponibles
}
in a typical case this function must build a two Collapsible ítems with a listview into each one.
My problem is in the try catch block, some times it Works fine, but another times it throw this exception:
Unable to get the property 'jQuery182044178615987382985' not defined or null reference
When try to initialize each list.
The collapsible elements allways initialize fine,
NOTE: If I visit the parent page of collapsible set at least one time, all things go fine.
Upvotes: 1
Views: 178
Reputation: 5534
Finally found a fix: All proccess of my data was performed on success
event of jQuery post
, just move it to done
event.
It seems a problem of synchro between my app and jQuery times.
Upvotes: 1