我在json遇到問題。這裏是我的list.js. 無論如何,我使用json2html.js html模板引擎。如何在JSON上添加超鏈接列表項?
var mylist = [
{ "name": "Pizza", "pic":"pizza.jpg", "type":"Food", "desc":"Bla bla","page":"pizza.html"},
{ "name": "Donut", "pic":"Donut.jpg", "type":"Food", "desc":"Bla bla.","page":"donut.html"},];
var rule_list =
{"tag": "li", "children": [
{"tag":"a","href":"src/$(page)",},
{"tag":"img","src":"res/i/${pic}","html":""},
{"tag":"div","class":"li-title","html":"${name}","children":[
{"tag":"p","html":"${type}","children":[
{"tag":"br","html":"${desc}"}
]}
]}
]};
var content_list = json2html.transform(mylist,rule_list);
document.write('<ul id="search_list" class="listview">'+ content_list + '</ul>');
,這是我的HTML
<!DOCTYPE html><html><head><title> test </title>
<script type="text/javascript" src="../js/json2html.js"></script>
<script type="text/javascript" src="../js/jquery.js"></script>
</head><body onload="loaded()">
<div id="mycontent">
<script type="text/javascript" src="fb-res.js"></script>
</div>
</body>
如何添加<a href="...html">
爲從JSON生成的每個<li>
?我已經在上面試過了,鏈接沒有出現。
對不起,我的英語不好。 謝謝你們
你試過我的代碼?我認爲它的作品... – 2014-09-05 11:33:41
仍然無法正常工作。什麼都沒發生。我已經嘗試了幾個小時。無論如何,我上面編輯了我的代碼,我希望你明白我的意思。謝謝:-) – user3408707 2014-09-06 05:04:45
你有無效的'rule_list'去掉最後一個']};',這裏是[工作版本](http://jsfiddle.net/d3jbsh07) – 2014-09-06 05:32:05