【发布时间】:2015-08-04 15:35:21
【问题描述】:
所以我一直在尝试在 Select2 组件中获取 Hirearchical 数据。但这似乎不起作用。我之前用过Select2,我觉得代码是一样的,在Select 2 4.0中数据不会显示出来。
var data = [
{
"description" : "Parent" ,
"children" : [
{
"description" :"Child 1",
"id" : "11",
"children" : [
{
"description" : "Grandchild 1",
"id" : "111"
},
{
"description" : "Grandchild 2",
"id" : "112"
}
]
},
{
"description" :"Child 2",
"id" : "12",
"children" : [
{
"description" : "Grandchild 1",
"id" : "121"
},
{
"description" : "Grandchild 2",
"id" : "122"
}
]
}
],
"id" : "1"
}
];
function descFormatResult(item) {
}
function descFormatSelection(item) {
return item.description;
}
$("#e10_2").select2({
matcher: function (term, text) {
return text.toUpperCase().indexOf(term.toUpperCase()) === 0;
},
placeholder: "Location",
minimumInputLength: 0,
data:{
results: data,
text : "description"
},
escapeMarkup: function (text) {
return text;
},
templateResult: descFormatResult
});
我确实有一个小提琴JSFiddle
任何帮助都会非常感谢。
【问题讨论】:
标签: jquery-select2 jquery-select2-4