开发者

Passing JSON Object to variable

I'm trying to pass the last ID variables which is returning by openURL method. This is the code:

" + ": 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-co开发者_如何学运维ntent 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 ;) )
        
    });
}

My problem is that to pass param.lastID to ReqID. I tried $("#reqID"+formCount).val() but it returns undefined, probably because asynchronous function. My question is, how to solve this problem?


The only parameter to an event handler is the event object.

If I understand your code correctly, you're trying to get the value you set when you created the object. You'll have to pull the data from the value:

var ReqID = $(this).val()

This will give you back a string, and it's up to you to make it work in your code.

EDIT:

Where is "#del" + formCount defined? You might need a different selector... maybe something like this:

var ReqID = $('reqID' + formCount).val();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜