我正在使用来自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