Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

jquery-ui, Use dialog('open') and pass a variable to the DIALOG

I have the following JS:

$('#listeditdialog').dialog('open');

Which opens the following dialog:

$('#listeditdialog').dialog({
    autoOpen: false,
    resizable: false,
    position: ['center',150],
    width: 450,
    open: function(event, ui) {
        $("#listeditdialog").load("/projects/view/tasks/ajax/?listid=" + XXXX);
    },
    close: function(event, ui) {
        $("#listeditdialog").html('<p id="loading"> </p>');
    }
});

My Question is when I use the dialog open function in another JS function, how can I pass a listID variable which I would get fom the click even bind that fired the dialog open func.

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If I understand you right, you want to have data that you have access to when you call $('#listeditdialog').dialog('open') that's available when the open event fires?

Something like this could help:

// where dialog is opened
$('#listeditdialog').data('listID', listIDVarOrSimilar); //assign the ID for later use
$('#listeditdialog').dialog('open')

// dialog definition
$('#listeditdialog').dialog({
    autoOpen: false,
    resizable: false,
    position: ['center',150],
    width: 450,
    open: function(event, ui) {
        var $led = $("#listeditdialog");
        $led.load("/projects/view/tasks/ajax/?listid=" + $led.data('listID'); //use the previously saved id
    },
    close: function(event, ui) {
        $("#listeditdialog").html('<p id="loading"> </p>');
    }
});`

http://api.jquery.com/data/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...