0
我有一種形式,一旦第一次下拉選擇,下一個將由第一個孩子填充。我需要通過已選擇的「分支」。問題是我需要傳遞一個字符串以外的東西到填充下一個選擇的選項的函數。我試圖使用jQuery的.data();方法,但我不斷收到錯誤。將數據傳遞給選擇選項,然後進入一個函數,jquery .data();
function Branch (name, level, parent) {
this.name = name;
this.level = level;
this.children = [];
this.parent = parent;
}
function makeNextOptions (branch){
var b = branch;
while (b) {
if (b.hasChildren()) {
f.append($("<select id="+l2+"></select>"));
var c = b.children;
j = c.length;
$("#"+l2).append($("<option></option>")
.attr("value", 2)//.id)
.text("text")
);
while (j--) {
$("#"+l2).append($("<option></option>")
.attr("value", c[j].name)//.id)
.text(c[j].name)
.data(c[j]);
)};
$("#"+l2).change(function() {
var sel = $("select option:selected").data();
console.log(sel);
createLevel(sel)
})
l--;
n = n.parent;
}else
{ n= null;
}
}
}
但我不斷收到一個錯誤,(「sel」)對象#沒有方法'hasChildren'。但是確實如此,因爲「sel」應該是另一個分支。