Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kendo ui 如何将值插入剑道组合框_Kendo Ui_Kendo Asp.net Mvc - Fatal编程技术网

Kendo ui 如何将值插入剑道组合框

Kendo ui 如何将值插入剑道组合框,kendo-ui,kendo-asp.net-mvc,Kendo Ui,Kendo Asp.net Mvc,如果我有一个剑道组合框,其中包含超过1个值,我想插入“-ALL”作为DataTextField和“9999”“作为DataValueField。目前,如果我只有一条记录,我会使用DataBound事件来测试它,如果它=1,那么我会根据这个值加载一个网格,但是如果长度>1,那么我会添加-All-。我不理解telerik所描述的插入 @(Html.Kendo().ComboBox() .Name("FAList") .Placeholder("Select F

如果我有一个剑道组合框,其中包含超过1个值,我想插入“-ALL”作为DataTextField和“9999”“作为DataValueField。目前,如果我只有一条记录,我会使用DataBound事件来测试它,如果它=1,那么我会根据这个值加载一个网格,但是如果长度>1,那么我会添加-All-。我不理解telerik所描述的插入

        @(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) {

    }
} 
答复如下:

结合您的代码:

if (e.sender.dataSource.view().length > 1) {   

$("#FAList").data("kendoComboBox").dataSource.add({ Text: "-All-",
Value: "0" }); 

}
差不多吧!我希望您能够实现这一点:)

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

例如:


我尝试了上面的建议,得到了一个未定义的列表,所以我尝试了insert,再次得到了一个未定义的列表?我的另一个想法是,在运行要添加到数据源的行之后,尝试调用组合框上的数据源绑定方法,以便它与新添加的数据源对象重新绑定?希望你能成功!
$("#FAList").data("kendoComboBox").input.attr("placeholder", "-All-");