在Yaws中输出Erlang列表的HTML数据 [英] Output data of Erlang List as a HTML in Yaws

查看:202
本文介绍了在Yaws中输出Erlang列表的HTML数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看下面的index.yaws文件

 < html> 
< body>
< h4>数据:< / h4>

< erl>
out(Arg) - >
Data = utilities:get_raw_data(),
{html,io_lib:format(〜p,[Data])}。
< / erl>

< erl>
out(Arg) - >
数据=实用程序:get_raw_data(),
列表:foreach(fun(X) - > {Id,Fname,Lname} = X,io:format(ID:〜p,[ ])end,Data)。
< / erl>

< / body>
< / html>

代码的第一部分正确运行,生成输出,如

  [{3,Matt,Williamson3},{2,Matt,Williamson2},{1,Matt,Williamson }] 

第二部分没有错误,但网页仍然空白。我相信

  io:format(ID:〜p,[Lname])

不打印输出到浏览器。



为了使其有效,我可以改变什么?

解决方案

尝试这个,而不是 foreach 行:(未测试)

  {html,lists:map(fun(X))> {Id,Fname,Lname} = X,io_lib:format(ID:〜p,[Lname])end,Data)}。 

也就是说,而不是使用 io格式,返回 {html,Iodata} 元组中的数据,如第一个< erl> 块。


Have a look at my index.yaws file below

<html>
<body>
    <h4>Data:</h4>

    <erl>
        out(Arg) -> 
            Data = utilities:get_raw_data(),
            {html, io_lib:format("~p", [Data])}.        
    </erl>    

    <erl>
        out(Arg) -> 
        Data = utilities:get_raw_data(),
        lists:foreach(fun(X) -> {Id, Fname, Lname} = X, io:format("ID: ~p ", [Lname]) end, Data).
    </erl>

</body>  
</html>

The first part of the code runs correctly producing output such as

[{3,"Matt","Williamson3"}, {2,"Matt","Williamson2"}, {1,"Matt","Williamson"}]

There is no error on the second part, but the web page remains blank. I believe the section

io:format("ID: ~p ", [Lname]) 

doesn't print out to the browser.

What do I get to change in order for it to work?

解决方案

Try this instead of the foreach line: (untested)

    {html, lists:map(fun(X) -> {Id, Fname, Lname} = X, io_lib:format("ID: ~p ", [Lname]) end, Data)}.

That is, instead of printing using io:format, return the data in a {html, Iodata} tuple, as in the first <erl> block.

这篇关于在Yaws中输出Erlang列表的HTML数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆