[英]Multiple parameters on cascade function
I need to pass more then one parameter in a cascade function: 我需要在级联函数中传递多个参数:
// Cascade function
(function ($) {
$.fn.cascade = function (options) {
var defaults = {};
var opts = $.extend(defaults, options);
return this.each(function () {
$(this).change(function () {
var selectedValue = $(this).val();
if (selectedValue == '') {
opts.childSelect.empty();
return;
}
var params = {};
params[opts.paramName] = selectedValue;
$.post(opts.url, params, function (items) {
opts.childSelect.empty();
if (opts.firstOption != "")
opts.childSelect.append(
$('<option/>')
.attr('value', '')
.text(opts.firstOption));
$.each(items, function (index, item) {
opts.childSelect.append(
$('<option/>')
.attr('value', item.Id)
.text(item.Name)
);
});
if (typeof (opts.callback) == "function") { opts.callback(); }
});
});
});
};
})(jQuery);
In the call, I need to pass the makeId and a categoryId value: 在通话中,我需要传递makeId和categoryId值:
// bind cascade Make dropdown
$("#Make_Id").cascade({
url: "/Ad/ListModelByCategoryByMake",
paramName: "makeId",
firstOption: 'Selecione o Modelo...',
childSelect: $("#Model_Id")
});
The call is made by post, so how can I call the cascade function with two parameters? 调用是通过post进行的,那么如何使用两个参数调用级联函数?
Thanks. 谢谢。
Function: 功能:
$.fn.cascade = function (options, param2) {
/// ....
}
call: 呼叫:
$("#Make_Id").cascade({
url: "/Ad/ListModelByCategoryByMake", // is better to use @Url.Action() helper here
paramName: "makeId",
firstOption: 'Selecione o Modelo...',
childSelect: $("#Model_Id")
}, 'your_second_param');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.