PDA

View Full Version : XTemplete foreach the data



mars0122
25 Aug 2011, 2:53 AM
data : [{
"tid":"75",
"uid":"1",
"content":"qawrernaernaern",
"roottid":"0",
"photo":null,
"replys":"12",
"forwards":"0",
"tousername":"",
"dateline":"1970-01-01 08:00:00",
"from":"web",
"type":"forward",
"nickname":"asd",
"face":"http:\/\/192.168.1.147\/t\/.\/images\/face\/c\/98\/1_s.jpg",
"validate":"1",
"subContent":false
},{
"tid":"144",
"uid":"1",
"content":"asdasd",
"roottid":"130",
"photo":null,
"replys":"0",
"forwards":"0",
"tousername":"",
"dateline":"1970-01-01 08:00:00",
"from":"web",
"type":"reply",
"nickname":"asd",
"face":"http:\/\/192.168.1.147\/t\/.\/images\/face\/c\/98\/1_s.jpg",
"validate":"1",
"subContent":[{
"tid":"130",
"nickname":"asd",
"validate":"1",
"content":"asdasd",
"replys":"15",
"forwards":"0"
}]
},{
"tid":"197",
"uid":"120",
"content":"\u6211\u81ea\u5df1\u7684\u8bc4\u8bba",
"roottid":"196",
"replys":"0",
"forwards":"0",
"dateline":"1970-01-01 08:00:00",
"from":"web",
"type":"forward",
"lat":"0",
"lng":"0",
"photo":null,
"nickname":"mars",
"face":"http:\/\/192.168.1.147\/t\/.\/images\/face\/f\/68\/120_s.jpg",
"validate":"0",
"subContent":[{
"tid":"196",
"nickname":"mars",
"validate":"0",
"content":"\u674e\u5c0f\u9f99",
"replys":"0",
"forwards":"1"
}]
}]


==============================================

+'<tpl for="subContent">'
+'<div>{nickname}:&nbsp;{content}</div>'
+'<tpl if="photo.length &gt; 0">'
+'<div><img src="{photo}" style="cursor:pointer;border:1px solid #eee;" /></div>'
+'</tpl>'
+'<div class="trans-commt">'
+'<img src="../images/transmisionAmount.png">{forwards}'
+'<img src="../images/commentsAmount.png">{replys}'
+'</div>'
+'</tpl>'

==================================================
Dear friends,my promblem is:
the "<tpl for="subContent">" cannot work well, it happended with nothing, no errors or warnings! Can you tell me why? Thanks sincerely!

vertex
25 Aug 2011, 3:17 AM
Try this,

"<tpl for=".">"

mars0122
25 Aug 2011, 7:38 AM
Thanks, but not the exact answer for the problem. I want to fetch the root and foreach the sub root of the first root.It's just like this:
+'<tpl for=".">'
+'<div>{nickname}:&nbsp;{content}</div>'
+'<tpl if="photo.length &gt; 0">'
+'<div><img src="{photo}" style="cursor:pointer;border:1px solid #eee;" /></div>'
+'</tpl>'
+'<div class="trans-commt">'
+'<img src="../images/transmisionAmount.png">{forwards}'
+'<img src="../images/commentsAmount.png">{replys}'
+'</div>
+'<tpl if "subContent != &quot;false&quot;">'
+'<tpl for="subContent">'
+'<div>{nickname}:&nbsp;{content}</div>'
+'<div class="trans-commt">'
+'<img src="../images/transmisionAmount.png">{forwards}'
+'<img src="../images/commentsAmount.png">{replys}'
+'</div>'
+'</tpl>'
+'</tpl>'
+'</tpl>'
======================================
Here there're two level foreach handler, is there another way?

jjerome
25 Aug 2011, 10:29 AM
Thanks, but not the exact answer for the problem. I want to fetch the root and foreach the sub root of the first root.It's just like this:
+'<tpl for=".">'
+'<div>{nickname}:&nbsp;{content}</div>'
+'<tpl if="photo.length &gt; 0">'
+'<div><img src="{photo}" style="cursor:pointer;border:1px solid #eee;" /></div>'
+'</tpl>'
+'<div class="trans-commt">'
+'<img src="../images/transmisionAmount.png">{forwards}'
+'<img src="../images/commentsAmount.png">{replys}'
+'</div>
+'<tpl if "subContent != &quot;false&quot;">'
+'<tpl for="subContent">'
+'<div>{nickname}:&nbsp;{content}</div>'
+'<div class="trans-commt">'
+'<img src="../images/transmisionAmount.png">{forwards}'
+'<img src="../images/commentsAmount.png">{replys}'
+'</div>'
+'</tpl>'
+'</tpl>'
+'</tpl>'
======================================
Here there're two level foreach handler, is there another way?

I see in your 10th line you are missing an '=' sign after 'if'.

It should be:

+'<tpl if="subContent != &quot;false&quot;">'

Try that and see if anything changes

mars0122
25 Aug 2011, 9:41 PM
The problem is not in the tpl, on the other hand, the model of data leaded the error.Just like the sample of the offical:

Ext.regModel('Generic', { fields: ['id', 'user_id', 'post_id'], hansMany: ['SubGeneric']});Ext.regModel('SubGeneric', { fields: ['replys','forwards','content'], belongsTo: 'Generic'});

Then,do the left as before via '<tpl for="subContent">'.