jQuery _renderItem未被调用 [英] JQuery _renderItem not being called
本文介绍了jQuery _renderItem未被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用_renderItem函数创建一个自定义ui-menu-item元素,但是在尝试之后我什至无法调用该函数.自动完成功能可以正常工作,但是好像不存在_renderItem函数.这是我的脚本部分
I am trying to create a custom ui-menu-item element using the _renderItem function but after may tries I can't get the function to even be called. The auto-complete is working but it is like the _renderItem function is not there. Here is my script scction
<script language="Javascript" type="text/javascript">
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
$j(document).ready(function() { //START of ready function
$j( "#custom-report" )
.autocomplete({
source: function( request, response ) {
$j.getJSON( "<?=$this->url(array("controller"=>"report", "action"=>"custom-autocomplete"))?>", {
term: extractLast( request.term )
}, response );
},
search: function() {
//Place holder
},
focus: function (event, ui) {
// Prevent the default focus behavior.
event.preventDefault();
},
select: function( event, ui ) {
var terms = split( this.value );
terms.pop();
terms.push( ui.item.value );
this.value = terms.join( ", " );
return false;
}
}).data("autocomplete")._renderItem = function (ul, item) {
return $("<li />")
.data("item.autocomplete", item)
.append("This is the text")
.addClass("tip")
.attr("desc", "This is the description")
.appendTo(ul);
};
}); //END of ready function
</script>
任何人都知道为什么这不起作用吗?
Anyone have any idea why this is not working?
推荐答案
我最终不得不这样做
$.ui.autocomplete.prototype._renderItem = function (ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.addClass("tip ui-menu-item")
.append("<a>" + item.label + "</a>")
.attr("desc", item.description) /* This is the filed that started the whole thing */
.attr("role", "presentation")
.appendTo(ul);
};
这篇关于jQuery _renderItem未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文