显示一系列对象作为表
我有一个candle
对象的数组,如下所示:
Pharo中有没有办法以表格格式显示数组?
| date | open | high | low | close |
|------------+------+------+-----+-------|
| 2018-12-28 | 10 | 20 | 30 | 40 |
| 2019-12-28 | 50 | 60 | 70 | 80 |
gtoolkit
gtoolkit Tour的幻灯片似乎提到了这一点:
但是,似乎我必须定义一个特殊集合来持有candle
对象,然后定义一个gtviewcandleson
方法>自定义蜡烛的渲染方式。
只是想知道是否有一种方法可以与正常数组一起使用,或者GToolKit方法是否是必需的。
I have an array of Candle
objects as shown below:
Is there a way in Pharo to display the array in a tabular format?
| date | open | high | low | close |
|------------+------+------+-----+-------|
| 2018-12-28 | 10 | 20 | 30 | 40 |
| 2019-12-28 | 50 | 60 | 70 | 80 |
gtoolkit
The gtoolkit tour has a slide that seems to mention this:
However, it seems that I'd have to define a special collection for holding Candle
objects and then define a gtViewCandlesOn
method on it to customize how the candles will be rendered.
Just wondering if there's an approach that will work with normal arrays or if the gtoolkit approach is the way to go.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于使用上下文。如果您也将其在其他活动上使用,则可以使用 gtoolkit 。 gtoolkit 是整个框架,将其仅用于此表格视图可能是非常过分的。
无论如何,我为Pharo Launcher命令行界面进行了类似的操作 - 称其为
ConsoleListformatter
。它非常简单地使用,您需要在蜡烛类上定义2种方法(#listprintattributeblocks:
#listprintattributelabels:
),将蜡烛集合设置为formatter实例。调用PrintList将完成这项工作。您可以在此处使用 consoleListformatter类
此外,如果要在检查员中打印为集合,则需要覆盖
#printon的原始实现:
() >在使用 gtoolkit Inspector 的情况下)在收集类中。相反,我将定义模型类,例如烛台
将使用实例var和candles的集合,然后您可以定义自己的#printon:
oncandlelist
>不干扰原始集合实现。让我知道,如果您需要更多详细信息!
干杯,
大卫
It depends on context of use. You can use GToolkit, if you use it on other activities as well. GToolkit is whole framework and probably it is quite overkill to use it just for this tabular view.
Anyway, I did something similar for Pharo launcher command line interface - calling it
ConsoleListFormatter
. It is pretty straightforward to use, you need to define 2 methods on your candle class (#listPrintAttributeBlocks:
#listPrintAttributeLabels:
) and set collection of Candles to formatter instance. Calling printList will do the job.You can use it here ConsoleListFormatter class
Furthermore, if you want to print as collection in the inspector, you would need to override original implementation of
#printOn:
(orgtViewCandlesOn:
in case of use GToolkit inspector) method on Collection class. Rather I would define model class, e.g.CandleList
that would use instance var with collection of candles, then you can define your own#printOn:
onCandleList
without interfering original collection implementation.Let me know, if you need more details!
Cheers,
David
要扩展检查员,请检查
:例如:
但是要激活此检查员选项卡,我们有此方法:
我为此做出此方法,您可以在您的项目中添加一些扩展方法,以便在数组类中为检查员添加一些扩展方法,并在拥有一个时打印您想要的任何内容阵列中的特殊对象。
To extend the inspector please check
For example:
But to activate this inspector tab we have this method:
I order to do that in your project you can add some extension methods for the inspector in Array class and print what ever you want when you have an special object in your array.