2

我试过使用下面的代码,我只是第一次完美绑定,当我试图选择另一个“类别”但产品没有显示在“产品下拉列表”中并且它也被禁用时。但我一直休息指出来自 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>

4

1 回答 1

2

尝试指定dataValueField

        $("#ddlCategory").kendoDropDownList({
            dataTextField: "CategoryName",
            dataValueField: "CategoryName",
            dataSource: dataSource,
            change: ChangeWeek
        });
于 2012-12-20T19:13:30.190 回答