這個問題是關於使用dust.js模板系統和子上下文中的數據路徑。我的意圖是支持i18n使用鍵到字符串的映射。dust.js:在作用域部分中使用路徑
由於數據是這樣的:
{i18n : { firstname : "First Name" },
people : [
{"name" : "Moe"},
{"name" : "Curly"}
]}
在灰塵,您可以使用部分列出的每個人:
{#people}
{name}
{/people}
你也可以使用一個路徑去的名字國際化字符串訪問:
{i18n.firstname}
但以下不起作用:
{#people}
{i18n.firstname}: {name}
{/people}
事實上,文件明確表示:
爲了避免脆性和混亂的引用,路徑從來沒有走回頭路了 上下文堆棧。如果您需要鑽取 父級上下文中可用的密鑰,請將該密鑰作爲參數傳遞。
所以我嘗試通過鍵作爲參數:
{#people i18n=i18n}
{i18n.firstname}: {name}
{/people}
但是,這是行不通的。當我與這對dust homepage實驗,我看到了編譯模板有這樣的代碼:
"i18n": ctx.get("i18n")
這讓我覺得上面的例子應該能正常運行。
那麼是什麼給?我該如何做這項工作?
注:以下確實工作:
{#people firstname=i18n.firstname}
{firstname}: {name}
{/people}
但是如果你需要在人內訪問了很多國際化的鍵背景下,這個不能很好地工作。
我還開了票在LinkedIn:欲瞭解更多信息,免受灰塵的LinkedIn叉看看這個wiki頁面GitHub有詳細的討論:https://github.com/linkedin/dustjs/issues/100#issuecomment-7615536 – JBCP 2012-08-09 16:25:13