0

我有一个剑道自动完成控件,它应该根据父剑道下拉列表的选定值填充其数据。

我想知道如何去做这件事。我正在使用 MVC 4 和 Razor 视图。

我试过这样做,但这没有用:

<div class="editor-field">
    @Html.Kendo().DropDownListFor(x => x.CustomerId).Name("customerDropDownList").Events(e=>e.Close("selectedItem")).Text(ViewBag.Customers[Model.CustomerId].TextValue).AutoBind(false).DataTextField("TextValue").DataValueField("Id").BindTo(ViewBag.Customers).HtmlAttributes(new { style = "width: 215px" })
</div>

<div class="editor-field">
    @Html.Kendo().AutoComplete().Name("customerOrders").Filter("startsWith").Placeholder("Customer Order Number.")
</div>


<script>
    $('#customersDropDownList').kendoDropDownList({
       close : function selectItem (e) {
            var item = e.item;
            var text = item.text();
            // Use the selected item or its text
        }
    });
</script>
4

1 回答 1

0

在下拉列表的更改(或 onClose 或 OnSelect)事件中,您可以使用本地或远程数据简单地设置自动完成的数据源,例如:

<div class="editor-field">
    @Html.Kendo().DropDownListFor(x => x.CustomerId).Name("customerDropDownList").Events(e=>e.Change("onDropdownChange")).Text(ViewBag.Customers[Model.CustomerId].TextValue).AutoBind(false).DataTextField("TextValue").DataValueField("Id").BindTo(ViewBag.Customers).HtmlAttributes(new { style = "width: 215px" })
</div>

<div class="editor-field">
    @Html.Kendo().AutoComplete().Name("customerOrders").Filter("startsWith").Placeholder("Customer Order Number.")
</div>    

<script>
    function onDropdownChange(e) {

        var selectedValue = this.value();    
        // If you have local data for every dropdown option, wrap them in individual datasource and switch accordingly.
        var dataSourceForoption1 = kendo.data.DataSource({ data: ["John", "Adam", "binbsr:)", "ginni"] });                        
        var autocomplete = $("#customerOrders").data("kendoAutoComplete");
        autocomplete.setDataSource(dataSourceForoption1); // For now, same dataSource for every option

    }    

</script>

希望能帮助到你。

于 2013-10-30T20:38:57.530 回答