我已经制作了这个JSON。但我发现了这个错误
a +="<div class=\"back\">"
+ "<a href=\"[[--CatAddress, s_tk, tplid:8270--]]\"><img src=\"[[--ImgRootDir--]]resource/image/button_back.png\" width=\"85px\" /></a>"
+ "</div>"
+ "<div class=\"bg\">"
+ "<img src=\"[[--ImgRootDir--]]resource/image/Film_Level.png\" width=\"590px\" height=\"600px\" />"
+ "</div>"
+ "<div class=\"lvle\">"
+ "<table width=\"84%\">"
+ "<tr>"
+ getSubsHTML(nodes[0].image, jsonStage.indexOf("2014_2012.json_0_0"),0)
+ getSubsHTML(nodes[1].image, jsonStage.indexOf("2014_2012.json_0_1"),1)
+ getSubsHTML(nodes[2].image, jsonStage.indexOf("2014_2012.json_0_2"),2)
+ getSubsHTML(nodes[3].image, jsonStage.indexOf("2014_2012.json_0_3"),3)
+ getSubsHTML(nodes[4].image, jsonStage.indexOf("2014_2012.json_0_4"),4)
+ "</tr>"
+ "<tr>"
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_0"))
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_1"))
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_2"))
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_3"))
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_4"))
+ "</tr>"
+ "<tr>"
+ getSubsHTML(nodes[5].image, jsonStage.indexOf("2014_2012.json_0_5"),5)
+ getSubsHTML(nodes[6].image, jsonStage.indexOf("2014_2012.json_0_6"),6)
+ getSubsHTML(nodes[7].image, jsonStage.indexOf("2014_2012.json_0_7"),7)
+ getSubsHTML(nodes[8].image, jsonStage.indexOf("2014_2012.json_0_8"),8)
+ getSubsHTML(nodes[9].image, jsonStage.indexOf("2014_2012.json_0_9"),9)
+ "</tr>"
+ "<tr>"
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_5"))
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_6"))
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_7"))
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_8"))
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_9"))
+ "</tr>"
+ "<tr>"
+ getSubsHTML(nodes[10].image, jsonStage.indexOf("2014_2012.json_0_10"),10)
+ getSubsHTML(nodes[11].image, jsonStage.indexOf("2014_2012.json_0_11"),11)
+ getSubsHTML(nodes[12].image, jsonStage.indexOf("2014_2012.json_0_12"),12)
+ getSubsHTML(nodes[13].image, jsonStage.indexOf("2014_2012.json_0_13"),13)
+ getSubsHTML(nodes[14].image, jsonStage.indexOf("2014_2012.json_0_14"),14)
+ "</tr>"
+ "<tr>"
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_10"))
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_11"))
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_12"))
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_13"))
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_14"))
+ "</tr>"
+ getSubsHTML(nodes[15].image, jsonStage.indexOf("2014_2012.json_0_15"),15)
+ getSubsHTML(nodes[16].image, jsonStage.indexOf("2014_2012.json_0_16"),16)
+ getSubsHTML(nodes[17].image, jsonStage.indexOf("2014_2012.json_0_17"),17)
+ getSubsHTML(nodes[18].image, jsonStage.indexOf("2014_2012.json_0_18"),18)
+ getSubsHTML(nodes[19].image, jsonStage.indexOf("2014_2012.json_0_19"),19)
+ "</tr>"
+ "<tr>"
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_15"))
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_16"))
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_17"))
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_18"))
+ getStageHTML(jsonStage.indexOf("2014_2012.json_0_19"))
+ "</tr>"
+ "</table>"
+ "</div>"
+ "<div class=\"left\">"
+ "<img src=\"[[--ImgRootDir--]]resource/image/Camera_kiri.png\" width=\"150px\" />"
+ "</div>"
+ "<div class=\"right\">"
+ "<img src=\"[[--ImgRootDir--]]resource/image/Camera_kanan.png\" width=\"150px\" />"
+ "</div>";
这是json
nodes: [
{
id: "2014_2012.json_0_0",
image: "_1396278834_af_org.png",
question: "1. What is this ?",
answer: "EXX",
hint: "asdadsadsadasdasdaads"
},
{
id: "2014_2012.json_0_0",
image: "_1396278834_af_org.png",
question: "1. What is this ?",
answer: "EXX",
hint: "asdadsadsadasdasdaads"
},
答案 0 :(得分:0)
好的,做了一些假设,但这很有效:http://jsfiddle.net/sp1nf731/3/
您是否正确引用了json变量?
var x = { nodes: [
{
id: "2014_2012.json_0_0",
image: "_1396278834_af_org.png",
question: "1. What is this ?",
answer: "EXX",
hint: "asdadsadsadasdasdaads"
},
{
id: "2014_2012.json_0_0",
image: "_1396278834_af_org.png",
question: "1. What is this ?",
answer: "EXX",
hint: "asdadsadsadasdasdaads"
}
] };
console.log( x.nodes[1].image );
这对我来说很好用
答案 1 :(得分:0)
我不知道你是如何获得节点的,但如果内联你需要
var nodes=[
{ .... },
{ .... },
{ .... }
]; // no comma on the last
这是一个缩短jQuery代码的建议
$(function() {
var $rowa=$("<tr/>"), $rowb=$("<tr/>"),
$.each(nodes,function(i,node) {
if (i>0 && i%5==0) {
$("#table1 tbody").append($rowa).append($rowb);
}
$rowa.append(getSubsHTML(node.image, jsonStage.indexOf("2014_2012.json_0_"+i),i);
$rowb.append(getStageHTML(jsonStage.indexOf("2014_2012.json_0_"+i));
});
// here you may test if i%5 !=0 and add the last rows
});