JQuery doesn't locate DOM elements when using Durandal's compose

前端 未结 2 1472
情歌与酒
情歌与酒 2021-02-11 09:05

I\'ve recently ported my company\'s project to Durandal using Knockout and JQuery. Straight to the problem: I need to initialize JQuery UI\'s datepicker using two HTML inputs. J

2条回答
  •  囚心锁ツ
    2021-02-11 09:27

    Pretty sure the problem is with this:

    users.SelectUser = function (user) {
        servers.CurrentUser(user);
    
        /* ... */
    
        $(function () {
            $("#datepickerFrom").datetimepicker({
                dateFormat: "d. m. yy",
                timeFormat: "HH:mm:ss",
                defaultDate: null
            });
    
            $("#datepickerTo").datetimepicker({
                dateFormat: "d. m. yy",
                timeFormat: "HH:mm:ss"
            });
        });
    }
    

    You have your jQuery datepicker init code inside a function. That means that it will only run when the SelectUser function gets called. Try moving that outside of any functions.

提交回复
热议问题