jQWidgets Forums

jQuery UI Widgets Forums Lists ListBox Code fires JSON data request twice

This topic contains 3 replies, has 3 voices, and was last updated by  support 12 years, 3 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • Code fires JSON data request twice #15333

    robrichard
    Member

    Hi guys – I must be doing something wrong here because in FireBug I can see the webservice is called twice from the following code:

    var lbsource = {
    datatype: “json”,
    datafields: [
    { name: ‘UserId’ },
    { name: ‘FirstName’ },
    { name: ‘LastName’ },
    { name: ‘Email’ }
    ],
    url: ‘@Url.Action(“GetUserList”)’
    };

    var values = [];

    var dataAdapter = new $.jqx.dataAdapter(lbsource, {
    async: false,
    autoBind: true,
    loadError: function (xhr, status, error) {
    alert(‘Error loading “‘ + lbsource.url + ‘” : ‘ + error);
    }
    });

    var records = dataAdapter.records;
    var length = records.length;
    for (var i = 0; i < length; i++) {
    values.push([records[i].UserId, records[i].FirstName, records[i].LastName, records[i].Email]);
    }

    $('#listbox').jqxListBox({
    selectedIndex: 0, source: dataAdapter, displayMember: "Email", valueMember: "UserId", itemHeight: 70, height: '100%', width: '100%',
    renderer: function (index, label, value) {
    var datarecord = values[index];
    var table = '‘ + values[index][1] + ” ” + values[index][2] + ‘‘ + values[index][3] + ”;
    return table;
    }
    });

    Any ideas?

    Code fires JSON data request twice #15334

    Peter Stoev
    Keymaster

    Hi robrichard,

    Remove “autoBind: true” from your code and it will be OK.

    Best regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Code fires JSON data request twice #15375

    robrichard
    Member

    Thanks Peter! Unfortunately, if I remove the autoBind: true, the dataAdapter contains no records, even though I can see the JSON string returning data in FireBug. Did I forget something else?

    Rob

    Code fires JSON data request twice #15378

    support
    Participant

    Hi robrichard,

    Please, take a look at the ListBox’s Binding to JSON sample. It shows how to use the jqxDataAdapter with the jqxListBox. Internally the jqxListBox calls the jqxDataAdapter’s dataBind method so it is not necessary to call it before that, too.

    Best regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.