【发布时间】:2012-03-19 18:33:08
【问题描述】:
我正在使用以下代码将我的 jQuery UI 自动完成项呈现为 HTML。 这些项目在自动完成控件中正确呈现,但我不断收到此 javascript 错误并且无法越过它。
Firefox 无法转换 JavaScript 参数
Chrome 无法设置未定义的属性“_renderItem”
donor.GetFriends(function (response) {
// setup message to friends search autocomplete
all_friends = [];
if (response) {
for (var i = 0; i < response.all.length - 1; i++) {
all_friends.push({
"label":"<img style='padding-top: 5px; width: 46px; height: 46px;' src='/uploads/profile-pictures/" +
response.all[i].image + "'/><br/><strong style='margin-left: 55px; margin-top: -40px; float:left;'>" +
response.all[i].firstname + " " + response.all[i].lastname + "</strong>",
"value":response.all[i].firstname + " " + response.all[i].lastname,
"id":response.all[i].user_id});
}
}
$('#msg-to').autocomplete({
source:all_friends,
select:function (event, ui) {
// set the id of the user to send a message to
mail_message_to_id = ui.item.id;
}
}).data("autocomplete")._renderItem = function (ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append($("<a></a>").html(item.label))
.appendTo(ul);
};
});
不知道为什么它会抛出这个错误,或者我必须做些什么才能克服它......感谢任何帮助。
【问题讨论】:
-
页面上是否有ID为
#msg-to的元素? -
是的...$("#msg-to") 是一个文本输入字段,.autocomplete 绑定到该字段。
-
仅供参考,对于使用 _renderItem() 方法填充原始 UL 以外的其他内容(即 SELECT OPTION)的任何人,我只能通过在其他对象已填充。
标签: javascript jquery jquery-ui jquery-autocomplete