【发布时间】:2016-11-02 13:29:16
【问题描述】:
我使用 Select2 如下:
$('select#fields').select2({
placeholder: 'Select a field',
data: data.fields
});
data.fields 是这样的 JSON:
"fields": [
{
"id": "companies_id",
"text": "companies_id",
"data-type": "int"
},
{
"id": "parent_companies_id",
"text": "parent_companies_id",
"data-type": "int"
},
{
"id": "client_of_companies_id",
"text": "client_of_companies_id",
"data-type": "int"
},
{
"id": "asset_locations_id",
"text": "asset_locations_id",
"data-type": "int"
},
{
"id": "companies_name",
"text": "companies_name",
"data-type": "varchar"
},
{
"id": "companies_number",
"text": "companies_number",
"data-type": "varchar"
}
]
id 和text 用于填充选项值,我可以使用第三个值data-type 并将其设置为<option> 的属性吗?如果有怎么办?可以给我举个例子吗?
【问题讨论】:
-
可以试试templating。
-
@lamelemon,实际上这里不需要模板。你可以查看我的答案:)
标签: javascript jquery select2 jquery-select2-4