4

我试图动态地更改资源数据源,但我所做的更改未应用于调度程序。Kendo UI Web调度程序 - 动态修改资源数据源

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

$("#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 
     } 
    ] 

}); 

而另一个控制被修改后,我尝试更换资源数据源,改变事件的颜色与该领域的值为1:“ CommertialRepresentativeId“为绿色。

_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); 

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

我会感谢一些帮助!

回答

2

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

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

如果你不想更换所有数据,但只改变一个项目,这应该也行:

// 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"); 
+0

我结束了除去最初包括后这样做元素:'schedulerControl.resources [0] .dataSource.add({text:“Rep 1”,value:1,color:“#00ff00”});'是否等价? –

+0

@ gaguevaras如果你只想改变一个项目,那会工作;如果您只想对项目进行小改动,我还编辑了另一个想法的答案 –