我有一个看起来像这样的模板(我也在使用 jQuery,因此我们的 GraphObject.make 不是$
but _
):
_(go.Panel, 'Table', {
itemTemplate: itemTemplate(_)
},
new go.Binding('itemArray', 'items')
)
当然那部分不是整个模板,我只包括重要的片段。
我现在要做的是制作一个itemTemplate(_)
实际上一行接一行返回的(取决于items
Array.
所以我试着有一个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 : 无行无列
- 面板:无行,无列
或者是否可以为每列返回两个单独的模板?
还是有其他我不知道的解决方案?