我对javascript有点新,需要为一个项目集成几个插件。有没有办法让customer_id
(在打开对话框窗口时获得,并通过自动完成建议)进入“创建新作业”按钮位置。
我想在用户点击“创建新作业”然后打开新对话窗口后关闭第一个对话框,但我想将customer_id
从第一个对话框窗口传递到第二个对话框窗口。可能有一些我可能无法理解的对话框和自动完成交互,我在调用customer_id
函数之前无法获得new_job()
。
$(function() {
$( "#dialog-name" ).dialog({
autoOpen: false,
})});
function customer_funct(){
$( "#dialog-name" ).dialog( "open" )
$(function() {
var name = $( "#name" );
$( "#name" ).autocomplete({
source: "suggest_name.php",
minLength: 2,
select: function( event, ui ) {
var customer_id = ui.item.customer_id;
// I am able to get customer_id here,
//now I need to pass it to the function below.
}
});
$( "#dialog-name" ).dialog({
autoOpen: false,
height: 300,
width: 500,
modal: true,
buttons: {
"Create new job": function() {
$( this ).dialog( "close" );
cust_name = (name.val());
// is there any way to get "customer_id" at this location
// before I call new_job() function after the user selects customer
// from the database and clicks "Create new job"?
new_job(customer_id, cust_name);
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});
答案 0 :(得分:0)
默认情况下,select事件ui参数仅包含“label”和“value”属性
JQuery UI Autocomplete Success Event
要访问自定义属性,您需要在通过ajax调用检索数据后显式添加它。与此post类似。
答案 1 :(得分:0)
我想我经过一番思考后自己回答了这个问题。如果其他人正在进行jQuery自动完成和对话交互,并且您需要使用上一个对话框窗口中的id值打开新对话窗口(在new_job(customer_id)中)并在成功时关闭上一个对话窗口:
$(function() {
$( "#dialog-name" ).dialog({
autoOpen: false,
})});
function customer_funct(){
$( "#dialog-name" ).dialog( "open" )
$(function() {
var name = $( "#name" );
$( "#name" ).autocomplete({
source: "suggest_name.php",
minLength: 2,
select: function( event, ui ) {
var customer_id = ui.item.customer_id;
new_job(customer_id);
$(this).val(''); return false;
}
});
$( "#dialog-name" ).dialog({
autoOpen: false,
height: 300,
width: 500,
modal: true,
buttons: {
"Create new job": function() {
alert('Please select customer or click "Add New" customer');
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});
}