Loading Datas With Ajax in EasyUI Combobox

6.1k Views Asked by At

How can I load json datas with ajax in EasyUI combobox?

    $('#cc').combobox({
        valueField: 'id',
        textField: 'text',
        data: function (request, response) {
            $.ajax({
                url: '@Url.Action("GetBranchesByCustomer","WidgetFeatures")',
                type: "POST",
                dataType: "json",
                data: { term: request.term },
                success: function (data) {
                    response($.map(data, function (item) {
                        return { id: item.id, text: item.name };
                    }))

                }
            })
        }
    });

I tried this script, but it didn't work. Where is my mistake?

Although I add "id" parameter like below, this script gives me this error: Uncaught TypeError: Cannot read property 'id' of undefined

<input id="cc" name="dept" value="aa">
1

There are 1 best solutions below

0
On

I solved the problem. It doesnt need ajax for load json datas. Because already "GetBranchesByCustomer" method returns json data. Scripts are below :

  $('#cc').combobox({
    valueField: 'id',
    textField: 'text',
    url: '@Url.Action("GetBranchesByCustomer","WidgetFeatures")'
});