我正在使用來自JSON的值填充Dojo組合框下拉菜單。下面 代碼工作得很好(在線JSON).....將外部JSON分配給變量
<script>
var magicvars = {
identifier: 'name',
label: 'name',
items: [
{name: "ZCCN_NO_1", label: "<img width='16px' height='16px' src='http://localhost:3000/static/images/eight_ball_16x16.png'/>ACCN_NO_1"},
{name: "CR_Local_ID", label:"<img width='16px' height='16px' src='http://localhost:3000/static/images/eight_ball_16x16.png'/>CR_Local_ID"}
]};
</script>
<div dojoType="dojo.data.ItemFileReadStore" data="magicvars" jsId="xvarStore2"></div>
然而,當我指定一個外部文件的JSON,不走,這是說,下拉填充。 外部文件standard.txt,看起來像這樣...
{
identifier: 'name',
label: 'name',
items: [
{name: "ZCCN_NO_1", label: "<img width='16px' height='16px' src='http://localhost:3000/static/images/eight_ball_16x16.png'/>ACCN_NO_1"},
{name: "CR_Local_ID", label:"<img width='16px' height='16px' src='http://localhost:3000/static/images/eight_ball_16x16.png'/>CR_Local_ID"}
]};
我的HTML調用道場的看起來像這樣..
<div dojoType="dojo.data.ItemFileReadStore" jsId="xvarStore2" url="http://localhost:3000/static/standard.txt">
</div>
內嵌工作正常,但外部調用沒有。道歉,如果這是一個補救問題,但我如何讀取外部文件並將其分配給「magicvars」。我只是不想用一堆內聯JSON混淆HTML。
任何意見表示讚賞。 Janie
請參閱下面答案中的註釋。你的JSON文件中的結尾分號是什麼給你的錯誤,而不是未加引號的屬性名稱。當然,應該引用適當的JSON - Dojo內部討論/辯論是否將xhr調用轉換爲使用JSON.parse - 因此,未引號的屬性名稱可能在2.0版本中不再有效。 – 2011-06-17 01:56:20