我有这样的功能:
function typeahead_fn(combo){
$(combo).typeahead({
highlight:true,
hint: false,
minLength: 0,
autoselect: false
},
{
name: "bh",
source: wrapper,
displayKey: 'itemName',
templates: {
// empty: [
// '<div class="empty-message">',
// 'no results found',
// '</div>'
// ].join('\n'),
suggestion: function(data){
return '<div class="comboRow"> <div class="comboColumn comboColumnEmpty"></div><div class="comboColumn comboColumnItemCode">' + data.itemCode + '</div> <div class="comboColumn comboColumnEmpty"></div> <div class="comboColumn comboColumnItemName">' + data.itemName + '</div> </div>';
}
},
limit: 1000
});
}
如果我这样称呼它,那么它可以正常工作:
typeahead_fn('.itemCombo');
如果我将其引用传递给插件则不起作用:
$("#tbl").editable({typeahead: typeahead_fn('.newItemCombo')});
更新
如果我以其他方式这样做,那么它可行:
$("#tbl").editable({typeahead: function typeahead_fn(){
$('.newItemCombo').typeahead({
highlight:true,
hint: false,
minLength: 0,
autoselect: false
},
{
name: "bh",
source: wrapper,
displayKey: 'itemName',
templates: {
// empty: [
// '<div class="empty-message">',
// 'no results found',
// '</div>'
// ].join('\n'),
suggestion: function(data){
return '<div class="comboRow"> <div class="comboColumn comboColumnEmpty"></div><div class="comboColumn comboColumnItemCode">' + data.itemCode + '</div> <div class="comboColumn comboColumnEmpty"></div> <div class="comboColumn comboColumnItemName">' + data.itemName + '</div> </div>';
}
},
limit: 1000
});
}
答案 0 :(得分:1)
如果要传递“reference”,则应删除函数名后的括号和参数,如:
$("#tbl").editable({typeahead: typeahead_fn});
如果你也想传递参数,你应该使用并将你的调用包装在一个匿名函数中,该函数将由“reference”传递:
$("#tbl").editable({typeahead: function () { typeahead_fn('.newItemCombo'); }});