使用 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"
}
]
}
]
}
最佳答案
尝试这样:
{
"results": [
{
"text": "Groupe 1",
"children": [
{
"id": "CA",
"text": "California"
},
{
"id": "CO",
"text": "Colarado"
}
]
},
{
"text": "Groupe 2",
"children": [
{
"id": "CA",
"text": "California"
},
{
"id": "CO",
"text": "Colarado"
}
]
}
]
}
我想你已经忘记了[
就在“结果”之后
关于jquery - 根据 JSON/Ajax 格式请求选择 2 optgroup 组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38763514/