将 haskell 列表数据渲染到网页
我正在使用 snap 框架和 haskell 创建简单的 Web 应用程序。我想知道如何将列表呈现到网页上,就像这样我有一个包含名字和姓氏的列表
[["firstName1","lastName1"],["firstName2","lastName2"],["firstName3","lastName3"]]
我想以两个方式显示这些信息列,有哪些可能的方法可以做到这一点,我能够绑定单值信息并显示在网页上。
I'm using snap framework and haskell to create simple web application.I want to know How can I render a list to web page,It is like this I have a list with first name and last name
[["firstName1","lastName1"],["firstName2","lastName2"],["firstName3","lastName3"]]
I want to display these information in two columns,What are the possible ways to do this,I was able to bind single value information and display on webpage.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Don 建议的 blaze-html 是实现此目的的一种方法,但我发现当我这样做时,我更倾向于通过将视图(在本例中为 HTML)嵌入到您的视图中来违反常用的 MVC 设计模式。哈斯克尔代码。在某些情况下,如果你只是想做一些快速而肮脏的事情,这可能就是你应该做的事情。但是,如果您希望以将视图与控制器分离的方式适应更大的应用程序,并允许不熟悉 Haskell 的设计人员使用它,那么您最好使用 Heist 模板系统。
我们在此处提供了抢劫教程。我最近还写了一系列关于此类事情的博客文章。 本系列的第二篇文章尤其可能是与你的问题最相关。下面是一些执行您想要的操作的代码:
在使用
bindSplice "names" nameSplice
将名称 splice 绑定到应用程序中的某个位置后,您可以从如下模板中获取此数据:也就是说,网页设计师可以完全控制名称的显示方式。如果他们需要更改显示以显示“姓氏,名字”格式的无序列表,那么在这里很容易做到,而无需重新编译您的应用程序。
Don's suggestion of blaze-html is one way to do it, but I find that when I do it that way I have more of a tendency to violate the commonly used MVC design pattern by embedding the view (in this case the HTML) into your Haskell code. In some cases if you're just trying to do something quick and dirty this may be the thing to do. But if you want this to fit into a larger application in a way that separates the view from the controller and allows designers to work with it who are unfamiliar with Haskell, then you might be better off using the Heist template system.
We have a Heist tutorial here. I also recently wrote a series of blog posts about just this sort of thing. The second post in the series in particular is probably the most relevant to your question. Here's some code that does something like what you want:
After you bind the names splice somewhere in your application with
bindSplice "names" namesSplice
you can get at this data from a template like this:The nice thing about this is that the web designer has complete control over how the names are displayed. If they needed to change the display to say an unordered list in the format "lastname, firstname" that would be very easy to do here without needing to recompile your application.
我非常喜欢 blaze-html,它是一套出色的快速翻译组合器将 Haskell 数据类型结构化为 html。
它有一个很好的主页,里面有很多示例,如下所示:
生成一个
text
字符串包含此表:如果您可以从 snap 输出
text
,那么您应该没问题。I have a strong preference for blaze-html, as an excellent set of combinators for quickly translating structured Haskell data types into html.
It has a nice home with lots of examples, like so:
Generates a
text
string containing this table:If you can output
text
from snap, you should be good.