0
我正在使用select2 v4並嘗試使用本地(已加載)選項製作從屬列表。從屬列表no ajax
var list1 = [
{id: 42, name: 'xxx'},
{id: 43, name: 'yyy'}
];
var list2 = [
{id: 1, name: 'aaa', list1: 42},
{id: 2, name: 'bbb', list1: 42},
{id: 3, name: 'ccc', list1: 43},
{id: 4, name: 'ddd', list1: 43}
]
我想list2
依靠list1
我試圖用一個回調的data
:
$('#list1').select2({
data: list1
});
$('#list2').select2({
data: function() {
var list2_filtered = $.grep(list2, function (choice) {
return choice.list1 == $('#list1').val();
});
return list2_filtered;
}
});
,但它似乎並沒有被調用。
爲什麼我的回調函數從未被調用?
如何使這些本地列表依賴?