X-editable 如何随请求发送数据
X-editable how to send data with request
我有 4 个 selects,每个 select 都是基于前一个 selects 的 selection。我将如何发送带有源项目请求的动态数据?
我尝试了一个函数,但发现 jQuery getJSON() 是异步的,无法按我需要的方式工作。
这是我目前拥有的。是的,我知道,它也不起作用。
// Location_Site X-editable init
$("#location-aisle").editable({
url: BASE_URL + "item/edit_item",
title: "Site aisle",
params: {
type: "location-site"
},
sourceCache: false,
source: BASE_URL + "item/get_aisles",
sourceOptions: {
headers: {
"aisle-id": $("#location-site").val()
}
}
});
使用成功事件解决并像这样手动设置源参数。
// Location_Site X-editable init
$("#location-site").editable({
url: BASE_URL + "item/edit_item",
title: "Location site",
params: {
type: "location-site"
},
source: sites,
success: function (response, newValue) {
// Get aisles for site
$.getJSON(BASE_URL + "item/get_aisles/" + newValue, function(data) {
outputDebug(data);
// Load aisles into drop down
if (data && data.length > 0) {
$("#location-aisle").editable("option", "source", data);
$("#location-aisle").editable("enable");
} else {
window.alert("Failed to load aisles for selected site.");
}
}, "json");
}
});
下面是下一级下拉菜单,以提供更好的示例
// Location_Site X-editable init
$("#location-aisle").editable({
url: BASE_URL + "item/edit_item",
title: "Site aisle",
params: {
type: "location-aisle"
},
success: function (response, newValue) {
// Get columns for site
$.getJSON(BASE_URL + "item/get_columns/" + newValue, function(data) {
outputDebug(data);
// Load aisles into drop down
if (data && data.length > 0) {
$("#location-column").editable("option", "source", data);
$("#location-column").editable("enable");
} else {
window.alert("Failed to load columns for selected site.");
}
}, "json");
//
// Get rows for site
$.getJSON(BASE_URL + "item/get_rows/" + newValue, function(data) {
outputDebug(data);
// Load aisles into drop down
if (data && data.length > 0) {
$("#location-row").editable("option", "source", data);
$("#location-row").editable("enable");
} else {
window.alert("Failed to load rows for selected site.");
}
}, "json");
}
});
其他注意事项:此代码不检查和处理无效响应或无效变量值。
我有 4 个 selects,每个 select 都是基于前一个 selects 的 selection。我将如何发送带有源项目请求的动态数据?
我尝试了一个函数,但发现 jQuery getJSON() 是异步的,无法按我需要的方式工作。
这是我目前拥有的。是的,我知道,它也不起作用。
// Location_Site X-editable init
$("#location-aisle").editable({
url: BASE_URL + "item/edit_item",
title: "Site aisle",
params: {
type: "location-site"
},
sourceCache: false,
source: BASE_URL + "item/get_aisles",
sourceOptions: {
headers: {
"aisle-id": $("#location-site").val()
}
}
});
使用成功事件解决并像这样手动设置源参数。
// Location_Site X-editable init
$("#location-site").editable({
url: BASE_URL + "item/edit_item",
title: "Location site",
params: {
type: "location-site"
},
source: sites,
success: function (response, newValue) {
// Get aisles for site
$.getJSON(BASE_URL + "item/get_aisles/" + newValue, function(data) {
outputDebug(data);
// Load aisles into drop down
if (data && data.length > 0) {
$("#location-aisle").editable("option", "source", data);
$("#location-aisle").editable("enable");
} else {
window.alert("Failed to load aisles for selected site.");
}
}, "json");
}
});
下面是下一级下拉菜单,以提供更好的示例
// Location_Site X-editable init
$("#location-aisle").editable({
url: BASE_URL + "item/edit_item",
title: "Site aisle",
params: {
type: "location-aisle"
},
success: function (response, newValue) {
// Get columns for site
$.getJSON(BASE_URL + "item/get_columns/" + newValue, function(data) {
outputDebug(data);
// Load aisles into drop down
if (data && data.length > 0) {
$("#location-column").editable("option", "source", data);
$("#location-column").editable("enable");
} else {
window.alert("Failed to load columns for selected site.");
}
}, "json");
//
// Get rows for site
$.getJSON(BASE_URL + "item/get_rows/" + newValue, function(data) {
outputDebug(data);
// Load aisles into drop down
if (data && data.length > 0) {
$("#location-row").editable("option", "source", data);
$("#location-row").editable("enable");
} else {
window.alert("Failed to load rows for selected site.");
}
}, "json");
}
});
其他注意事项:此代码不检查和处理无效响应或无效变量值。