【问题标题】:GoJS: Filling a Table using an itemArrayGoJS:使用 itemArray 填充表格
【发布时间】:2015-08-20 07:46:33
【问题描述】:

我有一个看起来像这样的模板(我也在使用 jQuery,因此我们的 GraphObject.make 不是$ 而是_):

_(go.Panel, 'Table', {
      itemTemplate: itemTemplate(_)
    },
    new go.Binding('itemArray', 'items')
)

当然那部分不是整个模板,我只包括重要的sn-p。

我现在要做的是创建一个itemTemplate(_),它实际上是一个接一个地返回(取决于items 数组中有多少元素。

所以我尝试使用这样的itemTemplate()

itemTemplate = function(_) {
  return _(
      go.Panel,
      'Horizontal',
      {
        margin: 2
        col: 1
      },
      new go.Binding('row','row')
      _(
        go.Shape,
        'Rectangle',
        {
          stretch: go.GraphObject.Horizontal,
          height: 5
        }
      ),
      _(
        go.TextBlock,
        {
          margin: 2
        },
        new go.Binding('text', 't')
      )
  );
};

我突然意识到。使用这种方法,我需要返回 2 个面板才能获得预期的输出。

如果有人想知道为什么行上有一个绑定,我在上面的 go.Binding 中使用回调来解决这个问题,如下所示:

new go.Binding('itemArray', 'items',
        function(d) {
          for (i = 0; i < d.length; i++) {
            d[i].row = i;
          }
          return d;
        }
      )

所以我的问题是:是否可以在 itemTemplate 周围有一个包装面板?像这样?

  • 面板:表
    • 面板:无行,无列
      • 面板:行:1,列:1
      • 面板:行:1,列:2
    • NextPanel:无行无列

或者是否可以为每列返回两个单独的模板?

或者还有其他我不知道的解决方案吗?

【问题讨论】:

    标签: javascript gojs


    【解决方案1】:

    是的,Panel.itemTemplate 可以是 TableRow 类型的 Panel。然后,此面板的每个元素都可以适当地设置其列。该行是自动设置的。

    查看http://gojs.net/latest/intro/itemArrays.html的讨论和示例

    【讨论】:

    • 有点离题,但我的问题中有它,尽管我不知道它是否正确。当我有go.Binding("itemArray", "items", function(d){}) 函数中的 d 指的是什么?整个数组还是数组的一个索引(itemsitems[i])?
    • 转换函数的参数将是nodedata.items的值。
    • 顺便说一下,通常不希望在转换函数中有副作用。您不知道他们多久或何时会被调用。
    猜你喜欢
    • 2016-03-31
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-14
    相关资源
    最近更新 更多