我正在使用以下代碼將我的jQuery UI自動完成項目呈現爲HTML。 項目在自動完成控件中正確呈現,但我不斷收到此javascript錯誤,無法移過它。無法使用HTML設置未定義的jQuery UI自動完成屬性'_renderItem'
火狐無法轉換JavaScript參數
鉻無法設置未定義
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);
};
});
不確定的特性「_renderItem」爲什麼它是引發此錯誤,或者我必須做什麼通過它...任何幫助表示讚賞。
頁面上是否有Id##msg-to'的元素? – 2012-03-01 17:22:42
是的,有... $(「#msg-to」)是.autocomplete綁定到的文本輸入字段。 – 2012-03-02 01:49:35
這有助於:http://stackoverflow.com/questions/5590776/why-am-i-getting-this-js-error – Ilmars 2012-05-31 07:43:23