下拉列表的选定值显示在Kendo Mobile中的[对象对象]

时间:2012-12-20 09:08:05

标签: jquery kendo-ui

我尝试使用下面的代码我只是第一次绑定完美,当我试图选择另一个“类别”但产品没有显示在“产品下拉列表”中,它也被禁用。但我已经保持断点,来自Web服务的数据即将到来,但它没有刷新数据

在HTML中

 <body>
<select id="ddlCategory" style="width: 300px">
    <option>---Select---</option>
</select>
<select id="ddlProduct" style="width: 300px">
</select>
<script type="text/javascript">
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "WebService.asmx/GetCategory",
        dataType: "json",
        success: function (data) {
            var dataSource = [];
            for (i = 0; i < data.d.length; i++) {
                dataSource.push({ "category": data.d[i].category })
            };
            $("#ddlddlCategory").kendoDropDownList({
                dataTextField: "category",
                dataValueField: "category",
                dataSource: dataSource,
                change: ChangeWeek
            });
        },
        failure: function (msg) {
            alert(msg);
        }
    });

    //$("#ddlProduct").kendoDropDownList();      
    function ChangeWeek(e) {
        //var ddlProduct = $("#ddlProduct");
        var ddlCategory = $("#ddlCategory").data("kendoDropDownList");
        var dataItem = ddlCategory.text();
        $.ajax({
            type: "POST",
            url: "WebService.asmx/GetProduct",
            data: "{'Category':'" + dataItem + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: true,
            success: function (data) {
                debugger
                //$("#ddlProduct").empty();
                var dataSource = [];
                for (i = 0; i < data.d.length; i++) {
                    dataSource.push({ "product": data.d[i].product })
                };
                $("#ddlProduct").kendoDropDownList({
                    dataTextField: "product",
                    dataValueField: "product",
                    dataSource: dataSource,
                    //  isVisible: true
                });
            },
            failure: function (msg) {
                alert(msg);
            }
        });
    }
    var app = new kendo.mobile.Application();
</script>

1 个答案:

答案 0 :(得分:2)

尝试同时指定dataValueField

        $("#ddlCategory").kendoDropDownList({
            dataTextField: "CategoryName",
            dataValueField: "CategoryName",
            dataSource: dataSource,
            change: ChangeWeek
        });