我是Erlang /氮的初学者。 我正在通过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).
我试图以同样的方式来建立我的事件,但它不工作。 在我的代码中,警报将替换为包含接受投标的表单的Lightbox。 请帮助并告诉我我做错了什么。
我想你使用建议[记录](http://www.erlang.org/doc/programming_examples/records.html),而不是模式匹配在像'{项目,指数的元组, _,_,_,_,_,_,_} = X'。 – 2011-02-23 11:30:06
我会牢记这一点。关于事件创建问题的任何想法? – elimayost 2011-02-23 11:34:50