0
我設置在玉條件塊內部變量。 我有一些對象有零,一個或兩個不同類型的評級。 每個對象都有兩個<span>
標籤。如果評分不存在,span標籤將留空。否則,我將適當的評級插入到我的span標籤中。我需要這些變量供將來在DOM下進一步使用。爲什麼我的玉代碼產生不需要的文本節點?
您可以用下面的玉代碼在這裏嘗試:
http://cssdeck.com/labs/a5rru5vj
編輯:下面平凡解,如果離開這件事它可以幫助別人:d
//Jade
- var demo = [{rating1:'2.5'}, {rating2:3.333333}]
each obj in demo
if(obj.rating1 !== undefined)
- var r1 = obj.rating1 || ""
= r1
else
- var r1 = ""
= r1
if(obj.rating2 !== undefined)
- var r2 = String(obj.rating2).slice(0,3)
= r2
else
- var r2 = ""
= r2
div.objIndex(data-obj=JSON.stringify(obj))
span.myRating= r1
span.googleRating= r2
// output html (with whitespace cleaned up)
// Note that Jade is writing the variables into the output, why, and how to avoid this?
<body>
2.5
<div data-obj="{"rating1":"2.5"}" class="objIndex">
<span class="myRating">
2.5
</span>
<span class="googleRating">
</span>
</div>
3.3
<div data-obj="{"rating2":3.333333}" class="objIndex">
<span class="myRating">
</span>
<span class="googleRating">
3.3
</span>
</div>
</body>