今天弄一个autocomplete 向后后台动态传递参数的问题
老的写法:
params: { "saleid": $("#divSalesman input[field='SalesmanId']").val() },
这样是不行的因为autocomplete() 方法不会每次都加载一遍,所以 $("#divSalesman input[field='SalesmanId']").val()获取的只是第一次加载的值
优化后的写法:
params: { "saleid": function () { return $("#divSalesman input[field='SalesmanId']").val(); }},
所以要使用function(){}再调用一次$("#divSalesman input[field='SalesmanId']").val();
$(".txtchoosecustomer", el).autocomplete({
serviceUrl: "/Custom/AutoComplate",
minChars: 1,
delimiter: /(,|;)\s*/, // regex or character
maxHeight: 400,
params: { "saleid": function () { return $("#divSalesman input[field='SalesmanId']").val(); }},
width: 250,
zIndex: 9999,
deferRequestBy: 0, //miliseconds
noCache: false,
onSelect: function (vl, vd) {
var rowdata = vd.data;
if (opts.callback != null) {
opts.callback(rowdata);
}
}
});