Kendo事件中的控件值是控件之前的值

Kendo control value in the event is the controls previous value

我想了解为什么这不起作用。如果我将 myTextBox 的值设置为 5,则触发更改事件。我的 myTextBox 的值为空。如果我将值更改为 10 然后再次触发事件,该值将是前一个 (5)。我将它与处理表单的众多文本框之一进行了比较,它们看起来是一样的。唯一的区别是包装器对象中的值 属性 设置在有效的对象中,但落后于无效的对象。深入研究两个对象元素 属性,我发现这些值是正确且最新的。任何帮助将不胜感激。

型号属性

    [UIHint("Decimal")]
    [Display(Name = "Example")]
    public decimal? MyTxt{ get; set; }

模板(Decimal.cshtml):

@model decimal?

@{
    var defaultHtmlAttributesObject = new { style = "width:100%" };
    var htmlAttributesObject = ViewData["htmlAttributes"] ?? new { };
    var htmlAttributes = Html.MergeHtmlAttributes(htmlAttributesObject, defaultHtmlAttributesObject);
}


@(Html.Kendo().NumericTextBoxFor(m => m)
            .Format("#.00")
            .HtmlAttributes(htmlAttributes)
)

UI声明

@Html.EditorFor(m => m.MyTxt, new { htmlAttributes = new { @style="width: 100%", @readonly = "readonly" } })

Javascript:

var myTextBox = $('#MyTxt').data('kendoNumericTextBox');

$(document).on('change', '#foo', function(){
       var test = myTextBox.value();
})

更新:

在文档就绪函数中,我像这样绑定更改事件:

$('#MyTxt').change({ source: $('#MyTxt'), destination: someObject, isTwoMan: true, crewType: LaborType.Set }, SomeCalcFunction);

jQuery 更改事件在 kendo 之前触发,因此延迟获得正确值。解决方法是阅读手册并以 kendo 方式

绑定到事件

问题出在我绑定更改事件的方式上。

$('#MyTxt').change({ source: $('#MyTxt'), destination: someObject, isTwoMan: true, crewType: LaborType.Set }, SomeCalcFunction);

将在 kendo 事件发生之前触发。以 kendo 方式更改它解决了我的问题

$("#MyTxt").bind("change", function (e) {

    var event = jQuery.Event('change', {
        source: $("#MyTxt"),
        destination: someObject,
        isTwoMan: true,
        crewType: LaborType.Set
    });
    SomeCalcFunction(event);
});