我是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