单击时修改vis.js数据集中的项目内容

时间:2015-10-20 12:51:37

标签: javascript

我们创建了一个包含以下项目的数据集:

SELECT
  *,
  DAU/WAU AS DAW_WAU,
  DAU/MAU AS DAW_MAU,
FROM (
  SELECT
    COALESCE(DAUDate,WAUDate,MAUDate) AS ReportDate,
    subreddit,
    EXACT_COUNT_DISTINCT(IF(DAUDate IS NOT NULL,author,NULL)) AS DAU,
    EXACT_COUNT_DISTINCT(IF(WAUDate IS NOT NULL,author,NULL)) AS WAU,
    EXACT_COUNT_DISTINCT(IF(MAUDate IS NOT NULL,author,NULL)) AS MAU,
  FROM (
    SELECT
      DDate,
      subreddit,
      author,
      Ind,
      DATE(IF(Ind=0,DDate,NULL)) AS DAUDate,
      DATE(IF(Ind<7,DATE_ADD(DDate,Ind,"Day"),NULL)) AS WAUDate,
      DATE(IF(Ind<30,DATE_ADD(DDate,Ind,"Day"),NULL)) AS MAUDate
    FROM (
      SELECT
        DATE(SEC_TO_TIMESTAMP(created_utc)) AS DDate,
        subreddit,
        author,
        INTEGER(SPLIT("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30",",")) AS Ind
      FROM
        [fh-bigquery:reddit_comments.2015_09],
        [fh-bigquery:reddit_comments.2015_08] ))
  WHERE
    COALESCE(DAUDate,WAUDate,MAUDate)<DATE(TIMESTAMP("2015-10-01")/*Current_Timestamp()*/)
  GROUP EACH BY
    1,
    2)
HAVING
  MAU>50000
ORDER BY
  2,
  1 DESC

现在我们要做的是能够点击var items = new vis.DataSet([ {id: 1, content: 'item 1', start: moment('8:00', "hh:mm"), end: moment('9:00', "hh:mm")}, {id: 2, content: 'item 2', start: moment('9:00', "hh:mm")}, {id: 3, content: 'item 3', start: moment('10:00', "hh:mm")}, {id: 4, content: 'item 4', start: moment('11:00', "hh:mm")} 例如更改其内容;我试过使用函数item1

dataset.update

但我们收到此错误:

  

第2项中缺少财产'内容'。

1 个答案:

答案 0 :(得分:0)

我没有测试过您的代码段,但问题可能是&#34; timeline.getSelection&#34;返回一组id和&#34; items.update&#34;只接受一个对象或一个对象数组作为&#34;数据&#34;参数。

解决方案1: 您需要循环选择数组,为每个条目创建一个数据对象并将其传递给&#34; items.update&#34;。

解决方案2: 准备一组对象并将数组传递给&#34; items.update&#34;。

参考: - visjs.org/docs/timeline/index.html#Methods - &gt; getSelection() - http://visjs.org/docs/data/dataset.html#Methods - &gt;更新(data [,senderId])