jQWidgets Forums

jQuery UI Widgets Forums Lists DropDownList .Net Json Problem as source

This topic contains 3 replies, has 2 voices, and was last updated by  Peter Stoev 12 years, 6 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • .Net Json Problem as source #10595

    fred
    Member

    Hello,

    I have a problem on setting the source of the Dropdownlist object.

    The ASP.Net Json Serializer returns like this..

    {"d":"[{"name":"test1"},{"name":"test2"}]"}

    After the script source below

     var source =
    {
    type: "GET",
    datatype: "json",
    id: "d",
    datafields:[{name: 'd'}]
    url: url,
    async: false
    };
    var dataAdapter = new $.jqx.dataAdapter(source);

    I can’t get my expected records. The code above returns

    [{"name":"test1"},{"name":"test2"}]

    Am I missing something?

    .Net Json Problem as source #10607

    Peter Stoev
    Keymaster

    Hi fred,

    As I understand, you want to display the array under the “d” . In order to achieve that, set the root of the source object to ‘d’.

    Example:

                  var json = '{ "d": [{"name":"test1"},{"name":"test2"}] }'; 
    var source =
    {
    type: "GET",
    datatype: "json",
    id: "d",
    datafields:[{name: 'name'}],
    localdata: json,
    root: 'd',
    async: false
    };
    var dataAdapter = new $.jqx.dataAdapter(source);

    Hope this helps.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    .Net Json Problem as source #10618

    fred
    Member

    Hi Peter,

    Thank you for your previous answer. That works on localdata option.

    However, I’m setting the source via url.. Which looks exactly like this:

     var source =
    {
    datatype: "json",
    root: "d",
    id: "id",
    datafields:
    [
    { name: 'id'},
    { name: 'd.mame' }
    ],
    url : 'Helper.svc/GetAutomationList',
    async: false
    };
    var d = new $.jqx.dataAdapter(source);
    $("#jqxWidget1").jqxDropDownList({ source: d});

    However the no data was returned. I’ve removed the

    root

    option and then gave me wrong JSON.

    (via Google Chrome Console)

    Object
    [
    d: "[{"id":1,"mame":"test1"},{"id":2,"mame":"test2"},{"id":3,"mame":"test3"},{"id":62,"mame":"test62"}]"
    __proto__: Object
    ]
    .Net Json Problem as source #10730

    Peter Stoev
    Keymaster

    Hi fred,

    I tried to load that from external file:

    d: "[{"id":1,"mame":"test1"},{"id":2,"mame":"test2"},{"id":3,"mame":"test3"},{"id":62,"mame":"test62"}]"

    The jQuery’s Ajax function throws “invalid character” error message. What is exactly the JSON returned by your service? I will need the exact JSON to test with it.

    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.