Kendo Scheduler,以编程方式设置值不更新dataModel

时间:2021-09-17 02:52:07
  • Kendo Scheduler via javascript
  • Kendo Scheduler通过javascript

  • Custom Edit Template
  • 自定义编辑模板

  • Edit Event -> programmatically setting a value on custom template controls
  • 编辑事件 - >以编程方式在自定义模板控件上设置值

  • Value shows in control, not included in dataModel
  • 值显示在控件中,不包含在dataModel中

I am implementing a Kendo Scheduler via javascript. I am using a custom edit template because there are several editable fields which are not native to the scheduler. One such field uses a kendo dropdownlist. I have subscribed to the edit event and in this event I get a handle on the dropdown and set its value. The UI element correctly shows the value I have set but when I save the scheduler the dropdownlist value is not included in the JSONified dataModel which I pass off to a CRUD handler. If I manually select an option from the dropdownlist it is included. I called the change event of the dropdownlist for giggles after the programmatic setting of its value. Still nothing. I tried this with textboxes, multiselections, numerictextboxes... they all fail to register their programmatically set values with the model.

我正在通过javascript实现一个Kendo Scheduler。我正在使用自定义编辑模板,因为有几个可编辑的字段不是调度程序的本机。一个这样的字段使用kendo下拉列表。我订阅了编辑事件,在这个事件中我得到了一个下拉菜单并设置了它的值。 UI元素正确显示了我设置的值,但是当我保存调度程序时,下拉列表值不包含在JSONified dataModel中,我将其传递给CRUD处理程序。如果我从下拉列表中手动选择一个选项,则会包含该选项。在编程设置其值后,我调用了下拉列表的更改事件。依然没有。我尝试使用文本框,多选项,数字文本框......它们都无法在模型中注册其编程设置值。

Ideas? Thanks.

$(function () {
    $("#scheduler").kendoScheduler({
        date: new Date("2015/4/14"),
        views: [
                "day",
                { type: "workWeek", selected: true, showWorkHours: true },
                "week",
                "month"
        ],
        allDayEventTemplate: $("#allDay-template").html(),
        eventTemplate: $("#event-template").html(),
        edit: function (e) {
            var location = e.container.find("[id=location]");
            location.kendoComboBox({
                dataTextField: "text",
                dataValueField: "value",
                dataSource: GetLocations,
                filter: "contains",
                suggest: true
            });

            var taskReminder = e.container.find("[id=AddTaskReminder]");
            taskReminder.kendoNumericTextBox({
                placeholder: "None",
                format: "n0",
                min: "0",
                decimals: "0",
                step: 15
            });

            var wnd = $(e.container).data("kendoWindow");
            wnd.setOptions({
                width: 800,
                height: 600
            });

          var clientID = $("#clientID");
         var ClientID = e.container.find("[id=ClientID]").data("kendoDropDownList");
         if (clientID.val() != "All") {
            ClientID.enable(false);
         }

            var Priority = $(e.container.find('[data-bind="value: Priority"]')).data("kendoDropDownList");
            if (e.event.isNew()) {
            if (clientID.val() != "All") {
                   ClientID.value(clientID.val());
                   e.container.find("[id=ClientID]").change();
            }

            var workerID = $("#workerID");
            var WorkerID = e.container.find("[id=workers]").data("kendoMultiSelect");

            if (workerID.val() != null) {
                       WorkerID.value(workerID.val());
                   e.container.find("[id=workers]").change();
            }

            Priority.value(2);
            (e.container.find('[data-bind="value: Priority"]')).change();
         }

            var taskName = e.container.find("[id=taskName]");
            taskName.kendoComboBox({
                dataSource: GetTaskTypes,
                dataTextField: "text",
                dataValueField: "value",
                filter: "contains",
                suggest: true
            });

            var isAllDay = $(e.container.find('[id=isAllDay]'));
            var StartDateTime = $(e.container.find('[id=startdatetime]')).data("kendoDateTimePicker");
            var EndDateTime = $(e.container.find('[id=enddatetime]')).data("kendoDateTimePicker");
            var DueDateFirm = $(e.container.find('[id=DueDateFirm]'));
            var Reminder = $(e.container.find('[id=AddTaskReminder]')).data("kendoNumericTextBox")
            var TaskComment = $(e.container.find('[id=TaskComment]'));

            taskName.change(function () {
                $("#TaskTypeName").val($(e.container.find("[id=taskName]")).data("kendoComboBox").text());
                if ($(e.container.find("[id=taskName]")).data("kendoComboBox").select() != "-1") {
                    if (confirm("Apply task type defaults (overriding previous values)?")) {
                        $.ajax({
                            type: "GET",
                            cache: false,
                            url: "/home/schedule/remotetasks.asp?Action=GetDefaultTaskTypeValues&DefaultTask=" + $(taskName).val(),
                            success: function (data) {
                                DS = JSON.parse(data);

                                Priority.value(DS[0].Priority);

                                if (DS[0].AllDayEvent == "True") {
                                    isAllDay.prop("checked", true);
                                }
                                else {
                                    isAllDay.prop("checked", false);

                                    if (DS[0].DefaultStartTime != "") {
                                        var d = new Date(StartDateTime.value());
                                        d.setHours(DS[0].DefaultStartHour);
                                        d.setMinutes(DS[0].DefaultStartMinute);
                                        StartDateTime.value(d);
                                    }

                                    if (DS[0].DefaultEndTime != "") {
                                        var d = new Date(EndDateTime.value());
                                        d.setHours(DS[0].DefaultEndHour);
                                        d.setMinutes(DS[0].DefaultEndMinute);
                                        EndDateTime.value(d);
                                    }
                                }
                                isAllDay.change();

                                Reminder.value(DS[0].DefaultReminderMinutes);
                                TaskComment.val(DS[0].TaskComment);
                            }
                        });
                    }
                }
            });
        },
        save: function (e) {
            if (e.container != null) {
            // AssignedTaskName req val

                // Dates req val
                var isAllDay = e.container.find("[id=isAllDay]");
                var startdatetime = e.container.find("[id=startdatetime]");
                var startdate = e.container.find("[id=startdate]");
                var enddatetime = e.container.find("[id=enddatetime]");
                var startdatereq = e.container.find("[id=startdatereq]");
                var enddatereq = e.container.find("[id=enddatereq]");

                var isAllDay = $(startdate).is(":visible");

                if (isAllDay) {
                    if ($(startdate).val() == "") {
                        //alert('invalid startdate');
                        e.preventDefault();
                        if ($(startdatereq).hasClass('hidden'))
                            startdatereq.removeClass('hidden');
                    }
                    else {
                        //alert('valid startdate');
                        if (!$(startdatereq).hasClass('hidden'))
                            startdatereq.addClass('hidden');
                    }
                }
                else {
                    if ($(startdatetime).val() == "") {
                        //alert('invalid startdatetime');
                        e.preventDefault();
                        if ($(startdatereq).hasClass('hidden'))
                            startdatereq.removeClass('hidden');
                    }
                    else {
                        //alert('valid startdatetime');
                        if (!$(startdatereq).hasClass('hidden'))
                            startdatereq.addClass('hidden');
                    }
                    if ($(enddatetime).val() == "") {
                        //alert('invalid enddatetime');
                        e.preventDefault();
                        if ($(enddatereq).hasClass('hidden'))
                            enddatereq.removeClass('hidden');
                    }
                    else {
                        //alert('valid enddatetime');                        
                        if (!$(enddatereq).hasClass('hidden'))
                            enddatereq.addClass('hidden');
                    }
                }
            }
        },
        editable: {
            template: kendo.template($("#customEditorTemplate").html())
        },
        moveEnd: function (e) {
            if (!confirm("Are you sure you want to update this event?")) {
                e.preventDefault();
            }

        },
        resizeEnd: function (e) {
            if (!confirm("Are you sure you want to update this event?")) {
                e.preventDefault();
            }
        },
        dataSource: {
            batch: true,
            sync: function () {
                this.read();
            },
            transport: {
                create: {
                    url: "/home/schedule/remotemanagecalendar.asp?Action=create",
                    dataType: "json"
                },
                read: {
                    url: "/home/schedule/remotemanagecalendar.asp?Action=read",
                    dataType: "json"
                },
                update: {
                    url: "/home/schedule/remotemanagecalendar.asp?Action=update",
                    dataType: "json"
                },
                destroy: {
                    url: "/home/schedule/remotemanagecalendar.asp?Action=destroy",
                    dataType: "json"
                },
                parameterMap: function (options, operation) {
                    if (operation === "read") {
                        var scheduler = $("#scheduler").data("kendoScheduler");

                        var result = {
                            start: scheduler.view().startDate(),
                            end: scheduler.view().endDate(),
                            clientid: $("#clientID").val(),
                            workerid: $("#workerID").val(),
                            taskstatus: $("#taskStatus").val()
                        }

                        return { models: kendo.stringify(result) };
                    }
                    else if (operation === "create" && options.models) {
                        return { models: kendo.stringify(options.models) + "||" + $("#TaskTypeName").val() };
                    }
                    else if (operation === "update" && options.models) {
                        return { models: kendo.stringify(options.models) + "||" + $("#TaskTypeName").val() };
                    }
                    else if (operation !== "read" && options.models) {
                        return { models: kendo.stringify(options.models) };
                    }
                }
            },
            schema: {
                model: {
                    id: "id",
                    fields: {
                        id: { from: "AssignedTaskID", type: "number" },
                        taskTypeID: { from: "TaskTypeID", type: "int" },
                        title: { from: "AssignedTaskName", type: "string" },
                        start: { from: "StartDateTime", type: "date", validation: { required: true } },
                        end: { from: "EndDateTime", type: "date" },
                        isAllDay: { from: "isAllDay", type: "boolean" },
                        dueDateFirm: { from: "DueDateFirm", type: "boolean" },
                        reminderMinutes: { from: "ReminderMinutes", type: "int" },
                        ClientID: { from: "ClientID", type: "int" },
                        Priority: { from: "Priority", type: "int" },
                        workers: { from: "Workers", nullable: true },
                        TaskComment: { from: "TaskComment", type: "string" },
                        locationid: { from: "LocationID", type: "string" }
                    }
                }
            }
        }
    });
});

var GetTaskTypes = new kendo.data.DataSource({
    transport: {
        read: {
            url: "/home/schedule/remotetasks.asp?Action=GetAddTaskTypes",
            dataType: "json"
        }
    }
});

var GetClientIDs = new kendo.data.DataSource({
    transport: {
        read: {
            url: "/home/schedule/remotetasks.asp?Action=GetAddClients",
            dataType: "json"
        }
    }
});

var GetPriorities = new kendo.data.DataSource({
    transport: {
        read: {
            url: "/home/schedule/remotemanagecalendar.asp?Action=GetPriorities",
            dataType: "json"
        }
    }
});

var GetAddWorkers = new kendo.data.DataSource({
    transport: {
        read: {
            url: "/home/schedule/remotetasks.asp?Action=GetAddWorkers",
            dataType: "json"
        }
    }
});

var GetLocations = new kendo.data.DataSource({
    transport: {
        read: {
            url: "/home/schedule/remotemanagecalendar.asp?Action=GetLocations",
            dataType: "json"
        }
    }
});

$("#AddTaskReminder").kendoNumericTextBox({
    placeholder: "None",
    format: "n0",
    min: "0",
    decimals: "0",
    step: 15
});

1 个解决方案

#1


I found the answer

我找到了答案

edit: function(e) { e.event.set('modelFieldName', 'value'); }

编辑:function(e){e.event.set('modelFieldName','value'); }

This sets it on the UI element as well as updates the dataModel. Hope it helps the next poor sap.

这将其设置在UI元素上以及更新dataModel。希望它有助于下一个可怜的闷棍。

#1


I found the answer

我找到了答案

edit: function(e) { e.event.set('modelFieldName', 'value'); }

编辑:function(e){e.event.set('modelFieldName','value'); }

This sets it on the UI element as well as updates the dataModel. Hope it helps the next poor sap.

这将其设置在UI元素上以及更新dataModel。希望它有助于下一个可怜的闷棍。