KendoUI DateTimePicker undefined on document.ready

前端 未结 3 794
故里飘歌
故里飘歌 2021-01-14 18:41

I have a Kendo DateTimePicker control in an mvc (asp.net) partial view that I am trying to access from document.ready():

@(Html.Kendo().DateTimePickerFor(vvm         


        
相关标签:
3条回答
  • 2021-01-14 19:01

    I usually use this to get the instance:

    var dtp = $('#dtpVisitStart').data('kendoDateTimePicker');

    0 讨论(0)
  • 2021-01-14 19:03

    Your original approach should work if you put the ready block at the bottom of the page, or at least below the widget initialization code (also see this section of the docs).

    If you put it above the @(Html.Kendo() section, TestDTP will run before the widget is initialized, since the widget initialization code is also wrapped in a jQuery ready block (and the various ready blocks are executed sequentially).

    0 讨论(0)
  • 2021-01-14 19:06

    What I ended up doing is initializing the datetimepicker from pure javascript and ditched the razor version:

    function TestDTP() {
        $("#dtpVisitStart").kendoDateTimePicker({
            format: "MM/dd/yyyy HH:mm tt",
            timeFormat: "HH:mm", 
            change: dtpVisitStart_Change, 
            value: "@(startTime)"
        });
        var dtp = $("#dtpVisitStart").getKendoDateTimePicker();
        debugger;
    }
    
    0 讨论(0)
提交回复
热议问题