Show Tag Count

已查看 23 次
跳至第一个未读帖子

KuoYing@Taiwan

未读,
2011年1月23日 04:41:122011/1/23
收件人 play-framework
Hi all:
In main.html file I want to show "itemTag" data, so I using...

>>
#{list allTags}
<div class="content_left_kind_list"
id="KDlist01">#{main.itemTag name:_.tagName /}(0)</div>
#{/list}
>>

It looks better, and allTags is query Tag class.....but my question is
"(0)"..I want to show how many items in the Tag...It will try to query
Item class..for example: Item.find("byItemTag",
_.tagNam ).fetch().size();

But this query string could replace "(0)"................

Nicolas Martignole

未读,
2011年1月23日 05:15:152011/1/23
收件人 play-fr...@googlegroups.com
Please read the documentation about the list tag

http://www.playframework.org/documentation/1.1/tags#list

#{list allTags, as:'currentTag'}
  <div class="content_left_kind_list" id="KDlist_${currentTag_index}">
    ${currentTag_index} ${currentTag.name}
  </div>
#{/list}

Nicolas

2011/1/23 KuoYing@Taiwan <stu93...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.


KuoYing@Taiwan

未读,
2011年1月23日 10:35:452011/1/23
收件人 play-framework
Hi..
I try to do this:
-------------------------
#{list items:models.Item.find('byItemTag', _name).fetch(), as:'tag'}
${tag.size()}
#{/list}
------------------------
But it can't shows size number. But when only #{tag} it is OK, but not
I want..I want size() number!!


On 1月23日, 下午6時15分, Nicolas Martignole <nico...@martignole.net> wrote:
> Please read the documentation about the list tag
>
> http://www.playframework.org/documentation/1.1/tags#list
>
> #{list allTags, as:'currentTag'}
>   <div class="content_left_kind_list" id="KDlist_${currentTag_index}">
>     ${currentTag_index} ${currentTag.name}
>   </div>
> #{/list}
>
> Nicolas
>
> 2011/1/23 KuoYing@Taiwan <stu93303...@gmail.com>
>
>
>
>
>
>
>
> > Hi all:
> > In main.html file I want to show "itemTag" data, so I using...
>
> > #{list allTags}
> >                <div class="content_left_kind_list"
> > id="KDlist01">#{main.itemTag name:_.tagName /}(0)</div>
> > #{/list}
>
> > It looks better, and allTags is query Tag class.....but my question is
> > "(0)"..I want to show how many items in the Tag...It will try to query
> > Item class..for example: Item.find("byItemTag",
> > _.tagNam ).fetch().size();
>
> > But this query string could replace "(0)"................
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "play-framework" group.
> > To post to this group, send email to play-fr...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > play-framewor...@googlegroups.com<play-framework%2Bunsubscribe@go oglegroups.com>
> > .

David Wursteisen

未读,
2011年1月23日 10:57:232011/1/23
收件人 play-fr...@googlegroups.com
#{list items:models.Item.find('byItemTag', _name).fetch(), as:'tag'}

I don't think that a view is a good place to do a database query. 

I suggest you to do your query in your controller, then render your view with your list : 

// in your controller
public static void myView() {
        List myList = models.Item.find('byItemTag', _name).fetch();     

        render(myList);

}



// in your view  (ie : myView.html)
list size = ${myList.size()}
iterate over my list : 
#{list items:myList, as:'tag'}
     a tag ==> ${tag}
#{/list}
2011/1/23 KuoYing@Taiwan <stu93...@gmail.com>
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.

KuoYing@Taiwan

未读,
2011年1月23日 11:48:402011/1/23
收件人 play-framework
But this tag is on the main.html Template >"< how to query in my
controller??

On 1月23日, 下午11時57分, David Wursteisen <david.wurstei...@gmail.com>
wrote:
> #{list items:models.Item.find('byItemTag', _name).fetch(), as:'tag'}
>
> I don't think that a view is a good place to do a database query.
>
> I suggest you to do your query in your controller, then render your view
> with your list :
>
> // in your controller
> public static void myView() {
>         List myList = models.Item.find('byItemTag', _name).fetch();
>
>         render(myList);
>
> }
>
> // in your view  (ie : myView.html)
> list size = ${myList.size()}
> iterate over my list :
> #{list items:myList, as:'tag'}
>      a tag ==> ${tag}
> #{/list}
> 2011/1/23 KuoYing@Taiwan <stu93303...@gmail.com>

Marcus Downing

未读,
2011年1月28日 05:14:122011/1/28
收件人 play-fr...@googlegroups.com
You mean it's on every page that uses main.html, and you need to do the query on all of them? I believe you should add a method to your controller like this:
@Before static void fetchList() {
List myList = models.Item.find('byItemTag', _name).fetch();
renderArgs.put('myList', myList);
}

This will get run for every action in your controller, and the myList variable will be available in all the views. David is right, you shouldn't do database queries in the view.
回复全部
回复作者
转发
0 个新帖子