Javascript 未调用JQuery\u renderItem
我正在尝试使用_renderItem函数创建自定义ui菜单项元素,但在五月尝试之后,我甚至无法调用该函数。“自动完成”功能正在运行,但好像没有_renderItem功能。这是我的脚本Javascript 未调用JQuery\u renderItem,javascript,jquery,jquery-ui,Javascript,Jquery,Jquery Ui,我正在尝试使用_renderItem函数创建自定义ui菜单项元素,但在五月尝试之后,我甚至无法调用该函数。“自动完成”功能正在运行,但好像没有_renderItem功能。这是我的脚本 <script language="Javascript" type="text/javascript"> function split( val ) { return val.split( /,\s*/ ); } function extractLast( term ) {
<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>
有人知道这为什么不起作用吗?这取决于jQuery UI版本,在较新的版本中,对象模型会发生更改,请参见: jQueryUI站点上的示例基于jQueryUI1.10 1.9和次要:
.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及下一步:
.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);
};
我最后不得不这么做
$.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);
};
将AJAX与嵌入式PHP结合使用有什么意义?$this->url是有效的JSON吗?选中,这将允许您将变量传递给客户端,这样您就可以将JS与PHP解耦。是的,这一切都可以工作,只是它完全忽略了Zend PHP应用程序中包含的_remderItem函数。您使用的是什么版本的jquery ui?