4

我有一个需要放在地图上的坐标列表。julius 是否可以迭代列表?现在我正在 hamlet 中创建一个隐藏表并在 julius 中访问该表,这似乎不是一个理想的解决方案。有人能指出更好的解决方案吗?谢谢。

编辑:为列表传递一个 JSON 字符串(julius 可以读取)似乎解决了我的问题。

4

1 回答 1

2

据我所知,您不能直接遍历 julius 中的列表。但是,您可以使用该Javascript类型的 Monoid 实例来完成类似的效果。例如:

import Text.Julius
import Data.Monoid
rows :: [Int] -> t -> Javascript
rows xs = mconcat $ map row xs
  where
    row x = [julius|v[#{show x}] = #{show x};
|]

然后,您可以rows xs在通常放置 julius 块的任何地方使用。例如,在 ghci 中:

> renderJavascript $ rows [1..5] ()
"v[1] = 1;\nv[2] = 2;\nv[3] = 3;\nv[4] = 4;\nv[5] = 5;\n"
于 2012-05-22T00:57:16.780 回答