我有一个使用自动完成功能的功能,但是我需要能够动态更改返回列,是否有人知道这种语法? 所以在这个例子中我想用i.return_id替换“i.id”。 我试过i.return_id,我[return_id],我[return_id],我。[“+ return_id +”],我。“+ return_id +”....用完选项。
function _autocomplete(element, type, pageid, tableid,return_name, return_id) {" +
"alert(element);" +
"if (type == 2) {" +
"$(element) .autocomplete({" +
" source: function(request, response) {" +
" var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), \"i\"); " +
" $.ajax({" +
" url: 'dataServices/objects.asmx/InvokeData'" +
" ,data: JSON.stringify({ q: request.term ,pid:pageid,tid:tableid,filter:JSON.stringify([{field:{label:\"\",value:\"return_name\"},operate:{label:\"\",value:\"ct\"},value:{label:\"\",value:\"\"+request.term+\"\"}}]),order:\"\",cid:38, sid: 2,jqGridSubId:\"\",jqGridLevel:0 })" +
" ,dataType: 'JSON'" +
" ,type: 'POST'" +
" ,contentType: 'application/json;charset=utf-8'" +
" ,success: function(data)" +
" {" +
" _dataStore = null; _dataStore = data;" +
" response($.map(data.d, function (i, item) { " +
" return { " +
" label: \"[\" + i.id + \"] \" + item[\" + return_name + \"], value: \"[\" + i.id + \"] \" + i.[\" + return_name + \"] " +
" }" +
" }" +
" ))" +
" }" +
" });" +
"}})}" +
答案 0 :(得分:0)
如果我正确理解您的代码,您只会尝试返回与return_id匹配的记录,并将其传递给它。你能试试这个......
response($.map(data.d, function (i, item) {
if (i.id == return_id) {
return {
label: \"[\" + i.id + \"] \" + item[\" + return_name + \"], value: \"[\" + i.id + \"]
+ i.[\" + return_name + \"]
}
}
}));