我的代码有一些“怪异”的问题。 它主要是西class牙语,但我相信你会得到。
$('#favoritos').live( 'pagecreate',function(event){ var favoritos = false; var fav_bus = ''; var fav_bici = ''; if (!isLocalStorageAvailable()) // Si no hay Local Storage para qué queremos entrar aqui $.mobile.changePage('#errorFavoritos', { transition: "pop" }); else{ $.each(localStorage, function(index){ var itemKey = localStorage.key(index); if (itemKey.indexOf('fav')){ // Si es un favorito var splitted = itemKey.split('-'); var tipo = splitted[0]; var numero = splitted[2]; favs_locales[itemKey] = { 'numero' : numero, 'id' : itemKey }; if (tipo == 'bus'){ favoritos = true; fav_bus = '' + 'Parada ' + numero+ '
' + ''; pedirTiempos(numero).pipe(formatearTiempos).done(function(html){ fav_bus += html + '
'; }); } } }); // Ya tenemos los datos formateados console.log(fav_bus); if (fav_bus != ''){ $('#contentFavoritos').append( 'Paradas de Bus
' + '' + fav_bus + ''); } } });
这个问题出现在这个函数中:
pedirTiempos(numero).pipe(formatearTiempos).done(function (html) { fav_bus += html; });
fav_bus
后的fav_bus
(在函数中)没关系,但是在函数之后的console.log(fav_bus)
是错的。 就像它在function中没有改变一样。
我试图返回html
但它输出的是[Object, object]
(作为字符串)。
任何提示?
编辑:
我已经尝试将它存储到一个时态DOM元素中它没关系但是我无法输出那个HTML(虽然它就在那里)。
pedirTiempos(numero).pipe(formatearTiempos).done(function(html){ fav_bus += html + '