var jsons=[{},{}]; jsons[0].url="//www.VeVB.COm"; jsons[0].text="武林网"; jsons[1].url="http://www.lovewebgames.com"; jsons[1].text="我的网站"; var list=document.getElementById("list"); dojo.forEach(jsons,function(onejson){ var li=document.createElement("li"); li.innerHTML=dojo.string.substitute("<a href='${url}'>${text}</a>",onejson});,); list.appendChild(li);
var jsons=[{url:"//www.VeVB.COm",text:"武林网"},{url:"http://www.lovewebgames.com/",text:"我的网站"}]; 然后我们遍历这个数组,在这里我使用的是dojo的forEach方法,它有两个参数,一个是要遍历的对象,第二个是一个函数handle(你叫它句柄也好,叫它委托也行),它有个参数,就是遍历的每一项。最后我还用到了一个字符串模版来得到json里的属性值,${url}就相当于取了onjson.url的值,${text}=onejson.text。例子请点击这里