Kendo UI Web Scheduler - 动态修改资源数据源

4

我正在尝试动态更改资源数据源,但是我所做的更改未应用于调度程序。

我已创建了一个调度程序,如下所示:

$("#scheduler").kendoScheduler
({
    date: new Date(),
    startTime: new Date("2013/11/27 07:00 AM"),
    endTime: new Date("2013/11/27 06:00 PM"),
    height: "600",
    selectable: true,
    views: [
        "day",
        { type: "workWeek", selected: true },
        "week",
        "month",
        "agenda"
    ],

    editable: {
        template: kendo.template($("#schedulerTemplate").html())
    },
    dataSource: _dataSourceDetailedAppointmentScheduler,
    edit: _api.onEditScheduler,
    cancel: _api.onCancelScheduler,
    save: _api.onSaveScheduler,

    resources: [
        {
            field: "CommertialRepresentativeId", // The field of the scheduler event which contains the resource identifier
            title: "Representante Comercial", // The label displayed in the scheduler edit form for this resource
            dataSource: [
                {
                    text: "Representante 1", // Text of the resource instance
                    value: 1, // Identifier of the resource instance, use that value to assign an event to this instance.
                    color: "#ff0000" // Used as the background of events assigned to this resource.
                },
            ],
            multiple: false // Indicate the this is a multiple instance resource
        }
    ]

});

在修改另一个控件后,我尝试替换资源数据源,将“CommertialRepresentativeId”字段中事件值为1的颜色更改为绿色。

_dataSourceDetailedAppointmentScheduler.read();
var schedulerControl = $("#scheduler").data("kendoScheduler");
//Construir
var resourceDS = new kendo.data.DataSource(
    {
        data: [
            { text: "rep 1",
                value: 1,
                color: "#00ff00"
            }
        ]
    }

);
resourceDS.read();

schedulerControl.resources[0].dataSource = resourceDS;
schedulerControl.view(schedulerControl.view().name);

无法弄清楚为什么调度程序将继续以原始颜色显示事件。

我需要帮助!

3个回答

2

您应该使用resource.setDataSourceresource.dataSource.data()来更新配置:

var data = [{ text: "rep 1", value: 1, color: "#00ff00" }];
schedulerControl.resources[0].dataSource.data(data);

如果您不想替换所有数据,而只是更改一个项目,那么这也可以起作用: ```html

如果您不想替换所有数据,而只是更改一个项目,那么这也可以起作用:

```
// id if you have one, otherwise dataSource.at(index) if you know the index
var existingItem = schedulerControl.resources[0].dataSource.get(id);
existingItem.set("color", "#00ff00");

在删除最初包含的元素后,我最终做了这个:schedulerControl.resources[0].dataSource.add({text: "Rep 1", value: 1, color: "#00ff00"}); 这是否等效? - Gustavo Guevara
@gaguevaras 如果你只想改变一个项目,那也可以;如果你只想对一个项目进行小的更改,我还编辑了我的答案提供另一个想法。 - Lars Höppner

0

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接