gpt4 book ai didi

javascript - 未调用 JQuery _renderItem

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:34:42 25 4
gpt4 key购买 nike

我正在尝试使用 _renderItem 函数创建自定义 ui-menu-item 元素,但在尝试之后我什至无法调用该函数。自动完成功能正常,但好像没有 _renderItem 功能。这是我的脚本 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>

有人知道为什么这不起作用吗?

最佳答案

我最终不得不这样做

$.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);
};

关于javascript - 未调用 JQuery _renderItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18293878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com