Populate Select2 with JSON data from local variable?

Populate Select2 with JSON data from local variable?

havehave Posts: 2Questions: 1Answers: 0

Hi, I hope someone has a answer howto populate Select2 with JSON data from local variable on init?
Most of examples here are from Ajax call and its not available in my case. How do you do it when using JSON object?

example jsondata: [{"Text":"H224","Id":"0523129a-7a15-4852-b907-00b003ae0feb","Beskrivning":"Extremt brandfarlig vätska och ånga"}]

        var jsonData = '<%= Session["Example"] %>'; // This varible is Json like 
        editor = new $.fn.dataTable.Editor({
            "ajax": function (method, url, d, successCallback, errorCallback) {
                var output = { data: [] };

                if (d.action === 'create') {
                    var addedRow = d.data[Object.keys(d.data)[0]];
                    addedRow.id = 1,
                    output.data.push(addedRow);
                }
                successCallback(output);
            },
            "serverSide": true,
            "table": '#<%= gridRegKemikalie.ClientID %>',
            "fields": [{
                "label": "Cas-nummer:",
                "name": "cas_nr"
            },
            {
                "label": "Ämne:",
                "name": "amne"
            },
            {
                "label": "H-fras:",
                "name": "hfras",
                "type": "select2",
                "opts": {
                    "tags": true,
                    "multiple": true,
                    "tokenSeparators": [','],
                    "placeholder": "Välj H-fras",
                    "allowClear": true
                },
                    "options": [{} ] //Use  Here on init ??  Read from jsonData instead!!
            }

        ]
        });

Answers

  • havehave Posts: 2Questions: 1Answers: 0

    Since this question seems to be unpossible to solve for some reason, go ahead and delete it. I solved the issue by my self.

This discussion has been closed.