・セレクト:https://select2.github.io/のjQuery - ヘッダの問題をセレクト2アレイ
最終結果は、複数の選択ボックスの例https://select2.github.io/examples.htmlと同様であるべきです。
問題:ドロップダウンを表示していますが、すべてのオプションがオブジェクトオブジェクトです。
コード
$(document).ready(function() {
function attribute(text) {
this.text = text;
this.children = [];
this.addChild = function (tid, tvalue) {
var val = { id: tid, text: tvalue };
this.children.push(val);
}
}
$.get("/products/attributelist", function (data) {
var attributeList = [];
$.each(data.AttributeGroups, function (i, val) {
var tmpAttr = new attribute(val.Name);
$.each(val.Attributes, function (val1) {
tmpAttr.addChild(val1.Id, val1.Name);
});
attributeList.push(tmpAttr);
});
$(".js-example-basic-multiple").select2({
data: attributeList
});
});
});
あなたが適切な形式のためので、あなたがたAttributeList配列に機能(属性)のリストをプッシュし
{
text: 'Group label',
children: [
{
id: 'nested-1',
text: 'First nested option'
},
// ... more data objects ...
]
}
良い十分な答えを、これを試してみてください。各ループに対して、属性の2番目のものがインデックスパラメータなしでミスタイプされました –