我在我的網站中使用了Chosen Select Box Jquery插件。選擇中的選項會使用ajax進行更新,因此當您在1個框中選擇某個內容時,下一個框的選項會顯示出來。FireBug - TypeError:項目未定義
我已經差不多工作了,但是當我點擊第二個框選項第三個框選項不顯示。我得到在Firebug的錯誤說:
類型錯誤:項目是未定義
item.selected = TRUE;
它說它是在選擇框的js文件中。
JS =======================
Chosen.prototype.result_select = function(evt) {
var high, high_id, item, position;
if (this.result_highlight) {
high = this.result_highlight;
high_id = high.attr("id");
this.result_clear_highlight();
if (this.is_multiple) {
this.result_deactivate(high);
} else {
this.search_results.find(".result-selected").removeClass("result-selected");
this.result_single_selected = high;
this.selected_item.removeClass("chzn-default");
}
high.addClass("result-selected");
position = high_id.substr(high_id.lastIndexOf("_") + 1);
item = this.results_data[position];
item.selected = true; <---------- Error
this.form_field.options[item.options_index].selected = true;
if (this.is_multiple) {
this.choice_build(item);
} else {
this.selected_item.find("span").first().text(item.text);
if (this.allow_single_deselect) this.single_deselect_control_build();
}
if (!(evt.metaKey && this.is_multiple)) this.results_hide();
this.search_field.val("");
if (this.is_multiple || this.form_field_jq.val() !== this.current_value) {
this.form_field_jq.trigger("change", {
'selected': this.form_field.options[item.options_index].value
});
}
this.current_value = this.form_field_jq.val();
return this.search_field_scale();
}
};
我花了幾個小時試圖數字出來,但不能。任何幫助,將不勝感激。
你確定'results_data'不是空的嗎?如果是,它是否在'high_id.substr(high_id.lastIndexOf(「_」)+ 1)'的結果中有一個值? – Oded
@BenjaminGruenbaum我只是想嘗試一些事情。 –
@Oded我希望這聽起來不像一個愚蠢的問題,但我如何檢查它是否爲空。因爲我認爲它是在頁面加載時,但不晚於 –