简体   繁体   English

使用 jQuery 更新 Kendo 下拉列表值会导致未定义的元素和空字符串值

[英]updating Kendo Dropdown list values with jQuery results in undefined elements and empty string values

I have three kendo dropdown lists in my MVC view.我的 MVC 视图中有三个剑道下拉列表。 Their values are set to defined Enums.它们的值被设置为定义的枚举。 The dropdownlists correctly display the values and I can change/update if I select each one individually.下拉列表正确显示值,如果我单独选择每个值,我可以更改/更新。 However, I have a button which is used to update all 3 dropdownlists values to "All" call 'setToAll' which calls a jQuery function that sets the value for each dropdownlist by name(id)但是,我有一个按钮,用于将所有 3 个下拉列表值更新为“全部”调用“setToAll”,它调用一个 jQuery 函数,该函数按名称(id)设置每个下拉列表的值

These are my enums:这些是我的枚举:

public enum FilterEmailSignOffStatus
        {
            All = -1,
            NotSent = 0,
            Sent = 1

        }

        public enum FilterPdfSignOffStatus
        {
            All = -1,
            NotYetPrinted = 0,
            Printed = 1
        }

        public enum FilterCorrectionStatus
        {
            All = -1,
            NotCorrected = 0,
            Corrected = 1,
            Reprinted = 2
        }

Here is my View:这是我的观点:

 <div class="col-md-3 ">
                            @(Html.Kendo().DropDownList()
                            .Name("printStatus")
                            .DataValueField("Text")                            
.BindTo(Enum.GetNames(typeof(SignOffSheetController.FilterPdfSignOffStatus)).ToList())

                            )
                        </div>

                        <div class="col-md-3 ">

                            @(Html.Kendo().DropDownList()
                            .Name("correctionStatus")
                            .DataValueField("Text")
.BindTo(Enum.GetNames(typeof(SignOffSheetController.FilterCorrectionStatus)).ToList())
                            )
                        </div>

                        <div class="col-md-3 ">

                            @(Html.Kendo().DropDownList()
                            .Name("emailStatus")
                            .DataValueField("Text")
.BindTo(Enum.GetNames(typeof(SignOffSheetController.FilterEmailSignOffStatus)).ToList())
                            )
                        </div>

                        <div class="col-md-3 ">
                            <button id="setAllStatus" class="btn btn-default">Set to All</button>
                        </div>

Here is my jQuery function:这是我的 jQuery 函数:

$("#setAllStatus").click(function (e) {
        e.preventDefault();

        $("#printStatus").data("kendoDropDownList").value("All");
        $("#correctionStatus").kendoDropDownList().data("kendoDropDownList").value("All");
        $("#emailStatus").kendoDropDownList().data("kendoDropDownList").value("All");


    });

The dropdowns should all be updated to the "All" value, but they are instead updated to "" empty strings.下拉列表应全部更新为“全部”值,但它们改为更新为""空字符串。 Anybody able to lend an eye and advise me where I might be going wrong?任何人都能够注视并告诉我我可能会出错的地方?

Managed to fix and get the button working.设法修复并使按钮工作。 I removed the .DataValueField("Text") properties on each of the dropdownLists, they are all updating correctly now.我删除了每个下拉列表上的 .DataValueField("Text") 属性,它们现在都在正确更新。

Strange thing is this used to work in a previous version of Kendo.奇怪的是,这曾经在以前版本的 Kendo 中工作过。 After we updated to a newer version (2018.2.516) this problem came up.在我们更新到较新的版本(2018.2.516)后,出现了这个问题。 My thinking is that the DropDownLists are updated with "All" but then try to get .DataValueField and fail, thus becoming undefined ""我的想法是 DropDownLists 用“All”更新,然后尝试获取 .DataValueField 并失败,从而成为未定义的“”

@(Html.Kendo().DropDownList()
  .Name("printStatus")
//.DataValueField("Text")   --- **Removed this parameter**

  .BindTo(Enum.GetNames(typeof(SignOffSheetController.FilterPdfSignOffStatus)).ToList())

                            )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM