Getting undefined values when using XML datasource

2 posts, 0 answers
  1. Patrick
    Patrick avatar
    9 posts
    Member since:
    Oct 2011

    Posted 28 Oct 2011 Link to this post

    Hi, I'm trying to populate a dropdown list using XML that was retrieved from a web service which I pass two arguments to. The list seems to be displaying the right number of items, however they all appear as "undefined". Here is my code:

    $("#dropdownbox").kendoDropDownList({
        dataSource: new kendo.data.DataSource({
            dataTextField: "name",
            dataValueField: "id",                       
            transport: {
                read: {
                    url: "WebService.asmx/GetDates",
                    data: {
                        startDate: "2010/10/20",
                        endDate: "2012/10/20"
                    }   
                }
            },
            schema: {
                type: "xml",
                data: "NewDataSet/dates",
                model: {
                    fields: {
                        building_name: "name/text()",
                        building_id: "id/text()"
                    }
                }
            }
     
        })                       
    });

    Here is the XML that is returned by the web service:

    <NewDataSet>
        <dates>
            <id>4</id>
            <name>TestItem1</name>
        </dates>
        <dates>
            <id>5</id>
            <name>TestItem2</name>
        </dates>
    </NewDataSet>

    Any help would be appreciated!
  2. Patrick
    Patrick avatar
    9 posts
    Member since:
    Oct 2011

    Posted 28 Oct 2011 Link to this post

    Nevermind I fixed it. I Had the dataTextField and dataValueField nested under datasource, dumb mistake. Here is the working code:

    $("#dropdownbox").kendoDropDownList({
        dataTextField: "name",
        dataValueField: "id",            
        dataSource: new kendo.data.DataSource({       
            transport: {
                read: {
                    url: "WebService.asmx/GetDates",
                    data: {
                        startDate: "2010/10/20",
                        endDate: "2012/10/20"
                    
                }
            },
            schema: {
                type: "xml",
                data: "NewDataSet/dates",
                model: {
                    fields: {
                        building_name: "name/text()",
                        building_id: "id/text()"
                    }
                }
            }
       
        })                     
    });
Back to Top