【问题标题】:how to insert value into the kendo combo box如何将值插入剑道组合框
【发布时间】:2016-10-21 19:58:04
【问题描述】:

如果我有一个包含超过 1 个值的剑道组合框,我想插入“-ALL-”作为 DataTextField,“9999”作为 DataValueField。目前,如果我只有一条记录,我使用 DataBound 事件对此进行测试,如果它 = 1,那么我会根据该值加载一个网格,但如果长度 > 1,那么我想添加 -All-。我不明白 Telik 所描述的插入。

        @(Html.Kendo().ComboBox()
      .Name("FAList")
      .Placeholder("Select Fiscal Agency...")
      .DataTextField("Text")
      .DataValueField("Value")
      .HtmlAttributes(new { style = "width:50%;" })
      .Filter("startswith")
      .AutoBind(true)
      .MinLength(3)
      .DataSource(source =>
      {
          source.Read(read =>
          {
              read.Action("GetUserAgencyList", "Entities");
          })
          .ServerFiltering(true);
      })
          .Events(e => e
            .Change("onFAChange")
            .DataBound("onFADataBound")
            )
)

然后是绑定数据的函数

        function onFADataBound(e) {
    // the agency list dropdown
    var combobox = $("#FAList").data("kendoComboBox");
    // if there is only a single record then set that in the combobox and load the grid based on that
    if (e.sender.dataSource.view().length == 1) {
        e.sender.select(0);
        var filter = this.value();
        $.get('/City/CityGrid_Read', { id: filter }, function (data) {
            var grid = $("#FollowUpGrid").data("kendoGrid");
            grid.dataSource.read();
        })
    }
    if (e.sender.dataSource.view().length > 1) {

    }
} 

【问题讨论】:

    标签: kendo-ui kendo-asp.net-mvc


    【解决方案1】:

    回复于:Adding an item dynamically in kendo combobox

    将其与您的代码结合起来:

    if (e.sender.dataSource.view().length > 1) {   
    
    $("#FAList").data("kendoComboBox").dataSource.add({ Text: "-All-",
    Value: "0" }); 
    
    }
    

    类似的东西!我希望你能实现这个:)

    另一种方法是在此事件方法中更改占位符文本,其中长度 > 1

    例如:http://www.telerik.com/forums/placeholder-text

    $("#FAList").data("kendoComboBox").input.attr("placeholder", "-All-");
    

    【讨论】:

    • 我尝试了上面的建议并得到了一个未定义的列表,所以我尝试了插入并再次得到了一个未定义的列表。
    • 也许尝试在新的代码行中将 Text 和 Value 大写?我的另一个想法是在运行添加到数据源的行之后,尝试在组合框上调用数据源绑定方法,以便它与新添加的数据源对象重新绑定?希望你能成功!
    猜你喜欢
    • 1970-01-01
    • 2014-02-06
    • 2016-12-26
    • 2013-06-26
    • 1970-01-01
    • 2012-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多