我正在使用 jQuery Gantt api,并且我想访问某些元素,但我不知道如何访问。
$(function() {
"use strict";
//var obj = JSON.parse($(".gantt").gantt);
$(".gantt").gantt({
source: [{
name: "Sprint 0",
desc: "Analysis",
values: [{
from: "/Date(1320192000000)/",
to: "/Date(1322401600000)/",
label: "Requirement Gathering",
customClass: "ganttRed"
}]
}],
navigate: "scroll",
scale: "weeks",
maxScale: "months",
minScale: "days",
itemsPerPage: 10,
onItemClick: function(data) {
alert("Item clicked - show some details");
},
onAddClick: function(dt, rowId) {
alert("Empty space clicked - add an item!");
},
onRender: function() {
if (window.console && typeof console.log === "function") {
console.log("chart rendered");
}
}
});
//alert("OK");
//var parsedData = JSON.parse();
//alert($(".gantt").gantt.source);
$(".gantt").popover({
selector: ".bar",
title: "I'm a popover",
content: "And I'm the content of said popover.",
trigger: "hover"
});
prettyPrint();
});
我找到了这个 ape 的静态示例,但我试图通过更改元素源的内容来绘制我自己的图表。 有人可以告诉我如何从甘特图对象中获取元素源吗?
最佳答案
你期待这个吗?
要通过对象访问gantt
元素,请尝试这样。
var ganttObj = $(".gantt").data("gantt");
或者尝试像这样为您的甘特图
创建实例
。
var ganttObj = $(".gantt").gantt("instance");
ganttObj.model.maxScale = "years" //To change `maxScale` property values dynamically
或者您也可以像这样直接访问您的元素。
例如:要将 maxScale
值从 月 更改为 年,您可以使用如下所示的方法。
$(".gantt").gantt({ maxScale: "years" });
如果这对您有帮助,请告诉我。
关于javascript - 我怎样才能访问JavaScript中的对象元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31404169/