我試圖傳遞最後的ID變量,這是由openURL方法返回的。這是代碼:將JSON對象傳遞給變量
" + ": function() {
formCount++;
$("#form tbody").append('<tr class="test"><td><input type="text" id="requirement'+formCount+'" class="text ui-widget-content ui-corner-all" /></td><td><input type="text" id="objects'+formCount+'" value="" class="text ui-widget-content ui-corner-all" /></td><td><input type="text" id="andor'+formCount+'" value="" class="text ui-widget-content ui-corner-all" /></td><td><input type="text" id="qty'+formCount+'" value="" class="text ui-widget-content ui-corner-all" /></td><td><div id="del'+formCount+'"><img src="themes/balance/images/delete_button.png" style="cursor:pointer; margin-left: 15px; margin-bottom: 5px;" alt="Delete" /></div></td></tr>');
/* Delete requirement from database */
$("#del"+formCount).click(function(param) {
$(this).parent().parent().remove(); // removes whole row in layout
var ReqID = ?????;
var query = '.requirements.deleteRequirement/'+gameID+'/'+ReqID+'';
openURL(url+query, function(param) { });
//alert(url+query);
});
/* Add requirement to database */
var query = '.requirements.createRequirement/'+gameID+'/Location/'+id+'/PLAYER_HAS_ITEM/1/1/1/1';
openURL(url+query, function(param) {
var CaughtID = new Boolean(param.lastID);
if(CaughtID.valueOf()) {
$(".test").append('<input type="hidden" id="reqID'+formCount+'" value="'+param.lastID+'" />')
}
param.lastID = 0; // important! Prevent to keep the last value in the object after add (check in DOM ;))
});
}
我的問題是,要param.lastID傳遞給REQID。我嘗試$(「#reqID」+ formCount).val(),但它返回未定義,可能是因爲異步函數。我的問題是,如何解決這個問題?
爲什麼你分配一個函數'「+」'?我希望這是一個類型的O ... – tjameson
「+」是一個按鈕: – user874565
所以,你正在分配一個功能的按鈕?那個匿名的? – tjameson