当同一个模板需要替换不同的数据显示的时候,如果数据量大点,用json很方便。
json对象:
var JSONObject= { "name":"Bill Gates", "street":"Fifth Avenue New York 666", "age":56, "phone":"555 1234567"};
json数组:
var employees = [ { "firstName":"Bill" , "lastName":"Gates" }, { "firstName":"George" , "lastName":"Bush" }, { "firstName":"Thomas" , "lastName": "Carter" } ];
employees[0].firstname="Bill"
employees[1].lastname="Bush"
多个数组:
var options = { "question" :[ { "title":"1.剧中Amy对Raj说Cop a feel 的意思是?", "option1":"抓住感觉", "option2":"像个警察", "option3":"揩油,占便宜", "option4":"受到侮辱", "correct":"3" }, { "title":"2.看着他一脸惊愕的表情,out of the park表达了什么?", "option1":"走出公园", "option2":"干得漂亮", "option3":"停在外面", "option4":"公园门票卖光了", "correct":"2" }, { "title":"3.face the music 怎么翻译才能配上他们的表情?", "option1":"面对音乐", "option2":"正视艺术", "option3":"看到乐谱", "option4":"承担责任", "correct":"4" }], result:[ { "title":"美剧俚语翻译优秀", "content":"你是字幕界的骄傲,你是地道美剧迷,你的词汇量超强,这是留美旅游的大杀器!这么拽的英语,证明你对美剧的热爱!把你的美剧推荐分享给朋友,也把这骄傲的成绩分享给朋友吧!" }, { "title":"美剧俚语翻译良好", "content":"你对美剧里的俚语有一定的了解,知道一些美国俚语的用法,再接再厉哦,分享给朋友,看看他们答几分?" }, { "title":"美剧俚语翻译不及格", "content":"亲,允许你重考一次!" }, { "title":"建议放弃美剧!!", "content":"" } ] };
options.result[1].content="你对美剧里的俚语有一定的了解,知道一些美国俚语的用法,再接再厉哦,分享给朋友,看看他们答几分?"
原文地址:http://blog.csdn.net/smy_yu/article/details/37901939