C# Kendo UI Asp.Net MVC 触发器不工作

C# Kendo UI Asp.Net MVC trigger not working

我有一个 Asp.Net MVC 应用程序,我在其中添加了一些 Keno UI (Telerik) 组件。其中之一是 Kendo 组合框,它工作正常,但没有触发更改事件。

这是我在 Asp.Net 中用于组合框的代码:

 @(Html.Kendo().ComboBox()
          .Name("EingangDrop")
          .Placeholder("Eingang durch...")
          .DataTextField("WSText")
          .DataValueField("ID")
          .HtmlAttributes(new { ng_model="Modell.EingangDurch" })
          .Filter("contains")
          .AutoBind(false)
          .MinLength(3)
          .DataSource(source =>
          {
              source.Read(read =>
              {
                  read.Action("GetVersand", "UserApi");
              })
              .ServerFiltering(false);
          })
    )

这工作正常,数据源设置得很好。 但是现在我遇到了 jquery 函数的问题。 我想通过 jQuery 更改 select,但它不起作用。

这是我的 jQuery 代码:

// fire change event (this is not working)
$("#EingangDrop").data("kendoComboBox").select(1);
$('#EingangDrop').trigger("change");

我正在触发 Api 中所述的更改事件,但这仍然没有显示。没有制造 selection。

我认为问题与数据源有关!当我在 jQuery 函数调用之前单击组合框,然后我在之后调用该函数时,就会生成 selection。但这只有在我之前点击 ComboBox 时才有效。我相信,如果我不点击它,它就不会加载数据源,然后就不会有 selection,因为此时数据源没有加载。

您没有为组合框绑定 change 事件。

尝试这样的事情:

    @(Html.Kendo().ComboBox()
              .Name("EingangDrop")
              .Placeholder("Eingang durch...")
              .DataTextField("WSText")
              .DataValueField("ID")
              .HtmlAttributes(new { ng_model="Modell.EingangDurch" })
              .Filter("contains")
              .AutoBind(false)
              .MinLength(3)
              .DataSource(source =>
              {
                  source.Read(read =>
                  {
                      read.Action("GetVersand", "UserApi");
                  })
                  .ServerFiltering(false);
              })
             .Events(e =>
             {
                e.Change("onChange");
             })
        )

还有一个 javascript 函数,它将在 changed 事件中被调用,例如:

function onChange() {
        kendoConsole.log("event: change");
    }

您可以在他们的 page.

上看到更多活动

为了在您的 ComboBox 上制作 select 等,您必须设置

AutoBind(true)

Setting autoBind to false is useful when multiple widgets are bound to the same data source. Disabling automatic binding ensures that the shared data source does not make more than one request to the remote service.

它应该看起来像:

@(Html.Kendo().ComboBox()
      .Name("EingangDrop")
      .Placeholder("Eingang durch...")
      .DataTextField("WSText")
      .DataValueField("ID")
      .HtmlAttributes(new { ng_model="Modell.EingangDurch" })
      .Filter("contains")
      .AutoBind(true)
      .MinLength(3)
      .DataSource(source =>
      {
          source.Read(read =>
          {
              read.Action("GetVersand", "UserApi");
          })
          .ServerFiltering(false);
      })
)