0

そのため、Select2 コンポーネントで階層データを取得しようとしています。しかし、それは機能していないようです。以前に 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

どんな援助も素晴らしいでしょうありがとう。

4

1 に答える 1