尝试在我的甘特图中实现视图选择功能。在documentation https://frappe.io/gantt中,它显示了示例:
gantt.change_view_mode('Week') // Quarter Day, Half Day, Day, Week, Month我有索引html:
<head>
<script src="dist/frappe-gantt.js"></script>
</head>
<script>
$(".btn-group").on("click", "button", function() {
$btn = $(this);
var mode = $btn.text();
gantt.change_view_mode(mode);
console.log(mode);
$btn.parent().find('button').removeClass('active');
$btn.addClass('active');
});
</script>gantt.change_view_mode(mode);返回以下错误:未捕获引用错误:未定义甘特图
frappe-gantt.js:
var Gantt = (function () {
'use strict';
...
refresh(tasks) {
this.setup_tasks(tasks);
this.change_view_mode();
}
change_view_mode(mode = this.options.view_mode) {
console.log(this.options.view_mode);
this.update_view_scale(mode);
this.setup_dates();
this.render();
// fire viewmode_change event
this.trigger_event('view_change', [mode]);
}
update_view_scale(view_mode) {
this.options.view_mode = view_mode;
if (view_mode === VIEW_MODE.DAY) {
this.options.step = 24;
this.options.column_width = 38;
} else if (view_mode === VIEW_MODE.HALF_DAY) {
this.options.step = 24 / 2;
this.options.column_width = 38;
} else if (view_mode === VIEW_MODE.QUARTER_DAY) {
this.options.step = 24 / 4;
this.options.column_width = 38;
} else if (view_mode === VIEW_MODE.WEEK) {
this.options.step = 24 * 7;
this.options.column_width = 140;
} else if (view_mode === VIEW_MODE.MONTH) {
this.options.step = 24 * 30;
this.options.column_width = 120;
} else if (view_mode === VIEW_MODE.YEAR) {
this.options.step = 24 * 365;
this.options.column_width = 120;
}
}
setup_dates() {
this.setup_gantt_dates();
this.setup_date_values();
}我尝试将其更改为Gantt.change_view_mode(mode);,但返回结果: TypeError: Gantt.change_view_mode不是一个函数
发布于 2021-02-11 01:42:22
我猜你已经弄明白了,但对于任何面临同样问题的人来说:你必须初始化Gantt opject,如下所示:
var tasks = [
{
id: 'Task 1',
name: 'Redesign website',
start: '2016-12-28',
end: '2016-12-31',
progress: 20,
dependencies: 'Task 2, Task 3'
},
{
id: 'Task 2',
...
}
]
var gantt = new Gantt("#id-of-your-svg-element", tasks);这是我从您也提到的文档中获得的信息:https://frappe.io/gantt
https://stackoverflow.com/questions/64714449
复制相似问题