Output data of Erlang List as a HTML in Yaws

送分小仙女□ 提交于 2019-12-13 06:44:02

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/16439505/output-data-of-erlang-list-as-a-html-in-yaws

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!