我的javascript代码中有以下部分,其中我想使用包含信息的变量来填充数据源而不是写下信息。我有办法吗?
...
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生成要在dataSource上显示的信息,并将其保存为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" });
在我指定dataSource的地方使用该变量
答案 0 :(得分: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"
}
}]