2

有没有办法在时间线中每行始终有一个项目?无论日期如何,我都不希望两个或更多项目共享同一行。

谢谢。

4

1 回答 1

1

您必须使用组,或者如果您已经将它们用于其他目的,则必须使用子组。
这是项目、组和子组的官方文档(我假设该网站不会很快过期......再次......)。

如果您可以使用群组

为每个项目指定不同的组。content如果您不想在时间轴的左侧为其添加标签,则可以将组设置为空字符串。
如果您想以特定方式排列组,请将排序函数指定为时间轴的选项groupOrder属性。例子:

var options = {
    // other properties...
    groupOrder: function (a, b) {
        if(a.content > b.content)// alphabetic order
            return 1;
        else if(a.content < b.content)
            return -1;
        return 0;
    }
};

如果您必须使用子组

创建项目时,将其放入它所属的组中,但还要为其指定subgroup属性,以便它是唯一的,就像项目的id. 例如,您可以使用 id 本身,或为其添加前缀或后缀。
在时间轴的选项中,将stackstackSubgroups属性设置为true
在每个组中,将subgroupStack属性设置为true并指定排序函数作为组的subgroupOrder属性。例子:

var group = {
    id: 1,
    content: 'example group',
    subgroupStack: true,
    subgroupOrder: function(a, b) {
        var tmp = a.start.getTime() - b.start.getTime();
        return tmp === 0 ? parseInt(a.id) - parseInt(b.id) : tmp;

        // if the start dates are the same, I compare the items' ids.
        // this is because due to a bug (I guess) the ordering of items
        // that return 0 in the ordering function might "flicker" in certain
        // situations. if you want to order the items alphabetically in that
        // case, compare their "content" property, or whatever other
        // property you want.
    }
};
于 2018-05-30T16:45:02.977 回答