나는 Erlang/Nitrogen의 초보자입니다. mnesia db로 입찰 시스템을 가지고 돌아 다니고 있습니다. 내 인덱스 페이지에서 다음 코드를 가지고 다양한 항목과 속성은 데이터베이스에서 동적으로 생성 얻을 :질소 - 동적으로 생성하는 이벤트
%% -*- 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).
내가 같은 방식으로 내 이벤트를 만들기 위해 시도했지만 작동하지 않았다. 내 코드에서 알림은 입찰을 수락 할 양식이 포함 된 라이트 박스로 대체됩니다. 도와주세요. 내가 뭘 잘못하고 있는지 말해주세요.
난 당신이 사용하는 것이 좋습니다 것 [기록] (http://www.erlang.org/doc/programming_examples/records.html) 대신'{항목, 색인 등의 튜플을 통해 일치하는 패턴, _, _, _}, _, _, _} = X'와 같은 형식을 사용합니다. –
나는 그것을 염두에 두겠다. 이벤트 생성 질문에 대한 아이디어가 있습니까? – elimayost