2016-08-22 34 views
0

我在我的JavaScript代碼中有以下部分,其中我想使用包含信息的變量來填充數據源而不是寫下信息。
有沒有辦法可以做到這一點?Syncfusion調度程序數據源

... 
resources: [ 
       { 
        field: "IdDepartament", 
        title: "Departament", 
        name: "Departaments", allowMultiple: false, 
        resourceSettings: { 
         dataSource: [ 
          //{ text: "Sales", id: 1, groupId: 1, color: "#100000" }, { text: "Programming", id: 2, groupId: 1, color: "#199999" }, { text: "Human Resources", id: 3, groupId: 1, color: "#299998" }, { text: "Support", id: 4, groupId: 1, color: "#399997" } 
         ], 
         text: "text", id: "id", groupId: "groupId", color: "color" 
        } 
       }, 
... 

我生成信息,以通過使用Ajax和它保存爲一個JavaScript變量,並顯示在執行console.log的信息,只是爲了確保我收到了正確的信息在數據源中。

編輯:
我想要做這樣的事情:

var departments = ({ text: "Sales", id: 1, groupId: 1, color: "#100000" }, { text: "Programming", id: 2, groupId: 1, color: "#199999" }, { text: "Human Resources", id: 3, groupId: 1, color: "#299998" }, { text: "Support", id: 4, groupId: 1, color: "#399997" }); 

,並使用該變量在哪裏指定數據源

回答

0

是的,這是可能的,其包含變量賦值填充dataSource的信息,而不是直接寫下如下所示的信息,

// variable with resource data information 
var resourceData = [ 
        { text: "Nancy", id: 1, groupId: 1, color: "#f8a398" }, 
        { text: "Steven", id: 3, groupId: 2, color: "#56ca85" }, 
        { text: "Michael", id: 5, groupId: 1, color: "#51a0ed" } 
] 

resources: [ 
        { 
         field: "ownerId", 
         title: "Owner", 
         name: "Owners", allowMultiple: true, 
         resourceSettings: { 
          dataSource: resourceData, // assigning the variable to resource data source 
          text: "text", id: "id", groupId: "groupId", color: "color" 
         } 
        }]