ここで尋ねた以前の質問からの回答は、非同期呼び出しについてますます学んでいるため、別の問題を引き起こしました。(前の回答が示したように)保存できるリストを達成する方法がまだわかりません。選択したリスト項目のデータを使用します。
$('#home').live('pageshow', function(){
// creating object
var customerList = JSON.parse('{"customerInAccount":[{"customer_name":"Jane Doe","auto_id":"21"},{"customer_name":"Jack Black","auto_id":"22"}]}');
// creating html string
var listString = '<ul data-role="listview" id="customerList">';
// running a loop
$.each(customerList.customerInAccount, function(index,value){
listString += '<li><a href="#" data-cusid='+this.auto_id+'>'+this.customer_name+'</a></li>';
});
listString +='</ul>';
console.log(customerList);
//appending to the div
$('#CustomerListDiv').html(listString);
// refreshing the list to apply styles
$('#CustomerListDiv ul').listview();
// getting the customer id on the click
$('#customerList a').bind('click',function(){
var customerID = $(this).data('cusid');
alert(customerID);
});
});
jsフィドルでhttp://jsfiddle.net/amEge/3/
このコードはうまく機能し、目的を達成することができますが、最初に ajax 呼び出しから customerList を設定する必要があります。しかし、「成功」機能からは、コードを機能させることができないようです。
$.post(postTo,{id:idVar} , function(data) {
customerList = data;
//alert(customerList);
})
コードを ajax 関数内に移動すると、機能しません。誰かが私を助けて、非同期呼び出しからこれを処理する方法を教えてくれるかどうか疑問に思っていましたか?
どうもありがとう