【发布时间】:2016-12-10 08:25:29
【问题描述】:
将 Select2 与 JSON/Ajax 调用一起使用,我正在尝试创建这样的组:
<optgroup label="Property Reference">
<option value="1">5742</option>
<option value="2">5788</option>
<option value="3">5762</option>
<option value="4">5711</option>
</optgroup>
我的问题is not available 的文档。
我设法开始工作的格式:
{
results: [
{
id: 'CA',
text: 'California'
},
{
id: 'CO',
text: 'Colarado'
]
}
}
但是这里没有组。
按照this question,我尝试了以下格式:
{
"results": {
"text": "Mountain Time Zone",
"children": [
{
"id": "CA",
"text": "California"
},
{
"id": "CO",
"text": "Colorado"
}
]
}
}
和
{
"results": {
"Mountain Time Zone": [
{
"id": "CA",
"text": "California"
},
{
"id": "CO",
"text": "Colorado"
}
]
}
}
和
{
"Mountain Time Zone": [
{
"id": "CA",
"text": "California"
},
{
"id": "CO",
"text": "Colorado"
}
]
}
但没有一个工作。有谁知道正确的格式是什么?
你可以在这里测试它:https://jsfiddle.net/5am4zda6/2/
编辑已解决:该死...忘记[]。
正确的格式是:
{
"results": [
{
"text": "Mountain Time Zone",
"children": [
{
"id": "CA",
"text": "California"
},
{
"id": "CO",
"text": "Colarado"
}
]
}
]
}
【问题讨论】:
-
它在小提琴上不起作用。
标签: jquery json ajax jquery-select2 select2