あなたのコードは、それがjQueryのモバイルの初期化処理の前に実行されて実行される場合によっては
は、ここでは、コードのビットがあります。 jsFiddleはデフォルトでload
イベントの発生後にコードを実行し、DOMがすべてセットアップされ、jQuery Mobileの初期化が完了しました。 @Phill PaffordのjsFiddle(http://jsfiddle.net/qSmJq/3/)を "onLoad"ではなく "no wrap(body)"で実行するように変更すると、報告しているのと同じエラーが発生します。だから私はlists.listview('refresh');
行を削除するか、document.ready
またはpageshow/pagecreate
イベントハンドラのいずれかの内側にコードを置くのいずれかをお勧めします:
var lists = $('#posicaoIntegradaActivosList, #posicaoIntegradaPassivosList, #posicaoIntegradaOutrosList');
lists.empty();
/* Fill the lists with jquery template */
//lists.listview("refresh");
ここでは、すぐにそれがブラウザによって解析されるように、コードを実行するためのjsfiddleです:http://jsfiddle.net/jasper/qSmJq/5/
または:ここ
$(function() {
var lists = $('#posicaoIntegradaActivosList, #posicaoIntegradaPassivosList, #posicaoIntegradaOutrosList');
lists.empty();
/* Fill the lists with jquery template */
lists.listview("refresh");
}
がdocument.ready
イベントハンドラにコードを包むためのjsfiddleです:http://jsfiddle.net/jasper/qSmJq/4/
または:ここ
$('#my-page-id').on('pagecreate', function() {
var lists = $('#posicaoIntegradaActivosList, #posicaoIntegradaPassivosList, #posicaoIntegradaOutrosList');
lists.empty();
/* Fill the lists with jquery template */
//lists.listview("refresh");
}
はpageshow
イベントを使用するためのjsfiddleです:http://jsfiddle.net/jasper/qSmJq/6/
そして、ここではpagecreate
イベントを使用するためのjsfiddleです:サイドノートでhttp://jsfiddle.net/jasper/qSmJq/7/
:場合jQuery Mobileが特定の要素を初期化したかどうかを検出したい場合、要素のjQuery Mobile固有のクラスを確認できます:
$(function() {
//cache lists
var lists = $('#posicaoIntegradaActivosList, #posicaoIntegradaPassivosList, #posicaoIntegradaOutrosList');
//iterate through the lists
lists.each(function (index, value) {
//cache this specific list
var $value = $(value);
/*add rows to this listview here*/
//check if the listview has been initialized by jQuery Mobile by checking for the existence of the `ui-listview` class
if ($value.hasClass('ui-listview')) {
//since the class was found, refresh the already initialized element
$value.listview('refresh');
} else {
//the class was not found, so initialize the widget
$value.trigger('create');
}
});
});
あなたのサンプルコードは、私がここでそれをテストしたように動作します:http://jsfiddle.net/qSmJq/1/とhttp://jsfiddle.net/qSmJq/3/そしてエラーなしで期待される結果を得る。どのバージョンのjQueryを実行していますか? RC3が必要1.6.4 –
HTMLコードを提供できますか?そして、あなたがリストを行うならどうでしょうか?listview(); beforeリスト。リストビュー( "リフレッシュ"); – GerjanOnline
Phill、あなたの例のロジックは私のコードと同じで、期待どおりに動作します。ここで何が間違っているのか分かりませんし、jQuery 1.6.4を使っています。 –