简体   繁体   中英

How to display few objects of the same class i Mustache template language

In the class Tg there is Public ListField1, which includes class Tzzz. I need that Tzzz was displayed in HTML so much times as is stated in List. There is HMTL code that displays one Tzzz:

<div class="section3">
        <span class="section3_label1">{{tv_stopH}}</span><span class="section3_label2">{{tv_sch}}</span>
    </div>
    <div class="section3_1">
    <div class="section3_1_textblock1">
        <span class="label_alt">{{arri}}</span><br />
        {{tv_add}}
    </div>
    <div class="section3_1_textblock2">
        <span class="label_alt">{{cont}}</span><br />
        {{tv_cont}}
    </div>
    <div class="section3_1_textblock1">
        {{#pic1}}
        <span class="label_alt">{{tv_refName1}}:</span>&nbsp;{{tv_ref1}}<br />
        {{/pic1}}        
    </div>

Class Tg:

public class Tg
{
    public List<Tzzz> Field1;

    public String Value1;
    public String Value2;
    ............

Class Tzzz:

public class Tzzz
{
public Integer tv_stopH;
public String tv_sch;
public String arri;
public String cont;
........

JAVA code for one object Tzzz:

    Template tmpl = Mustache.compiler().escapeHTML(false).compile(template);
    Map<String, Object> data = new HashMap<String, Object>();

    .......
    value = tzzz.tv_stopH;
    data.put("tv_stopH", value);

    value = tzzz.tv_sch;
    data.put("tv_sch", value);

    value = tzzz.arri;
    data.put("arri", value);

    value = tzzz.tv_add;
    data.put("tv_add", value);

    value = tzzz.cont;
    data.put("cont", value);


    if(tzzz.tv_refName1.length() > 0)
    {
        data.put("pic1", True);

        value = tzzz.tv_refName1;
        data.put("tv_refName1", value);

        value = tzzz.tv_ref1;
        data.put("tv_ref1", value);
    }

You use {{#list_key_name}}...{{/list_key_name}} .

So if you have a variable List<SomeObject> foo and you add that to the Map<String, Object> params; params.put("foo", foo) , then the template would look like this.

<ul>
    {{#foo}}
    <li><!--interpolate values from SomeObject --></li>       
    {{/foo}}
</ul>

These things are explained in the documentation . It should work across different implementations, unless the port for some reason has decided to break the "spec".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM