Nitrogen - 动态创建事件
我是 Erlang/Nitrogen 的初学者。 我正在玩弄 mnesia 数据库支持的投标系统。 在我的索引页面上,我有以下代码,并且从数据库动态创建各种项目及其属性:
%% -*- mode: nitrogen -*-
-module (index).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").
main() -> #template { file="./site/templates/bare.html" }.
title() -> "Meir Panim Gala Dinner silent auction".
body() ->
Header = [#panel{id=header, body=[#h1{text="Meir Panim Gala Dinner silent auction"}]}],
{atomic, Items} = item_database:get_all(),
Elements = lists:map(fun(X) ->
{item, Index, Title, _, Picture, _, _, Reserve, CurrentBid} = X,
#panel{id=items, body=[
#span{id=title, text=Title},
#image{id=image, image= "images/" ++ Picture},
#span{id=currentbid, text="Current bid: £" ++ integer_to_list(CurrentBid)},
#span{id=reserve, text="Reserve: £" ++ wf:to_list(Reserve)},
#link{id=showalert, text="More info / Place your bid", postback="showalert"++integer_to_list(Index)}
]
}
end, Items),
wf:f([Header, Elements]).
{atomic, Items} = item_database:get_all(),
Actions = lists:map(fun(X) ->
{item, Index, _, _, _, _, _, _, _} = X,
event("showalert"++integer_to_list(Index)) ->
wf:wire(#alert{text="action "++integer_to_list(Index)++" clicked"})
end, Items).
我尝试以相同的方式创建事件,但它不起作用。 在我的代码中,警报将替换为包含接受出价表单的灯箱。 请帮助并告诉我我做错了什么。
I am a beginner with Erlang/Nitrogen.
I am toying with a bidding system back by a mnesia db.
On my index page I have the following code and the various items and their properties get created dynamically from the database:
%% -*- mode: nitrogen -*-
-module (index).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").
main() -> #template { file="./site/templates/bare.html" }.
title() -> "Meir Panim Gala Dinner silent auction".
body() ->
Header = [#panel{id=header, body=[#h1{text="Meir Panim Gala Dinner silent auction"}]}],
{atomic, Items} = item_database:get_all(),
Elements = lists:map(fun(X) ->
{item, Index, Title, _, Picture, _, _, Reserve, CurrentBid} = X,
#panel{id=items, body=[
#span{id=title, text=Title},
#image{id=image, image= "images/" ++ Picture},
#span{id=currentbid, text="Current bid: £" ++ integer_to_list(CurrentBid)},
#span{id=reserve, text="Reserve: £" ++ wf:to_list(Reserve)},
#link{id=showalert, text="More info / Place your bid", postback="showalert"++integer_to_list(Index)}
]
}
end, Items),
wf:f([Header, Elements]).
{atomic, Items} = item_database:get_all(),
Actions = lists:map(fun(X) ->
{item, Index, _, _, _, _, _, _, _} = X,
event("showalert"++integer_to_list(Index)) ->
wf:wire(#alert{text="action "++integer_to_list(Index)++" clicked"})
end, Items).
I tried to create my events in the same manner but it was not working.
In my code the alerts will be replaced with lightboxes containing a form to accept bids.
Please help and tell me what I am doing wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,您可以通过“事件”捕获页面中的事件。
所以我会尝试类似:
并在向下捕获它:
更新:
这只是如何修复它的一个示例,这不是最好的方法。
As far as I know you catch events in page with "event".
so I would try something like :
and at down catch it with :
update:
this is only an example of how you can fix it, its not the best way.