より高いレベルから、私がやろうとしているのは、オブジェクトへの ID を含む JavaScript を介して投稿することです。
投稿するjqueryを作成するウィジェットに「PlayerId」を渡しています。
tableClickHandlerWidget :: String -> TableId -> PlayerId -> Maybe Int -> Widget
tableClickHandlerWidget elemId tid playerId seatId = do
let seatNumber = if seatId == Nothing
then "null"
else show $ fromJust seatId
let pid = fromPersistToJS $ unKey playerId
toWidget[julius|
$(function() {
$('#{show elemId}').click.post(
'@{GamingSessionsR}',
{ player: '#{pid}', table: '#{show tid}', seat:'#{seatNumber}' },
);
});
|]
toWidget[hamlet|something<br/>|]
fromPersistToJS :: PersistValue -> String
fromPersistToJS p = do
let (a) = fromPersistValue p
case a of
Left l -> T.unpack l
Right r -> r
fromPersistToJS から返されるのは、オブジェクト ID を文字列にできないという例外です。
ただし、URL は基本的に文字列であり、その中に ID が含まれています。だから私はこれが可能でなければならないと確信しています。
https://github.com/gdoteof/exodus/はレポ全体であり、私はこの投稿を作成しています
https://github.com/gdoteof/exodus/commit/4daa0a25a9f44c69cbdc5c0bb4e8aa4f6433de45