首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未调用JQuery _renderItem

未调用JQuery _renderItem
EN

Stack Overflow用户
提问于 2013-08-18 06:28:02
回答 2查看 1.8K关注 0票数 3

我正在尝试使用_renderItem函数创建一个自定义的ui-菜单项元素,但在尝试之后,我甚至无法让该函数被调用。自动完成功能正在工作,但好像_renderItem函数不在那里。这是我的脚本部分

代码语言:javascript
复制
<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>

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

EN

回答 2

Stack Overflow用户

发布于 2013-08-20 04:37:26

我最终不得不这么做

代码语言:javascript
复制
$.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);
};
票数 4
EN

Stack Overflow用户

发布于 2013-08-18 18:08:43

这取决于jQuery UI版本,在较新的版本中,对象模型会发生更改(请参阅:http://jqueryui.com/upgrade-guide/1.10/#autocomplete)。

jQuery UI站点上的示例基于jQuery UI 1.10。

1.9和次要版本:

代码语言:javascript
复制
.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);
    };

1.10及以下版本:

代码语言:javascript
复制
.data("ui-autocomplete")._renderItem = function (ul, item) {
        return $("<li />")
            .data("ui-autocomplete-item", item)
            .append("This is the text")
            .addClass("tip")
            .attr("desc", "This is the description")
            .appendTo(ul);
    };
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18293878

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档