jquery uses templates to dynamically add HTML elements, equivalent to the foreach in Jstl

Source: Internet
Author: User

jquery uses templates to dynamically add HTML elements

1, the development of the time to cycle to load the list, usually we use the page <c:foreach> tag loop loading the background data.

<C:foreachItems= "${srmodel.bplbatchplanitem}"var= "Items"Varstatus= "S">                        <TR>                        <TD><inputname= "ItemId"type= "checkbox"value= "${items.id}"Mtype= "${items.materialtype}" ></TD>                        <TD>${ITEMS.ATTR1}</TD>                         <TD>${items.materialcode}</TD>                        <TD>${items.materialtype}</TD>                        <TD>${items.materialname}</TD>                                                <TD>${items.specification}</TD>                        <TD>${items.normaldrawing}</TD>                        <TD>${items.unit}</TD>                        <Fmt:formatnumberpattern="#.########"value= "${items.bidnumber}"var= "Bidnumber"/>                         <TD>${bidnumber}</TD>                        <Fmt:formatnumberpattern="#.########"value= "${items.budgetprice}"var= "Budgetprice"/>                         <TD>${budgetprice}</TD>                        <Fmt:formatnumberpattern="#.########"value= "${items.budgetfreightprice}"var= "Budgetfreightprice"/>                         <TD>${budgetfreightprice}</TD>                        <Fmt:formatnumberpattern="#.########"value= "${items.budgetinstallprice}"var= "Budgetinstallprice"/>                         <TD>${budgetinstallprice}</TD>                        <Fmt:formatnumberpattern="#.########"value= "${items.budgettotalprice}"var= "Budgettotalprice"/>                         <TD>${budgettotalprice}</TD>                        <TD>${items.deliveryplace}</TD>                        <TD>${items.consignee}</TD>                        <TD>${items.deliverystatus}</TD>                        <TD>${items.deliveryconditions}</TD>                        <TD>${items.deliverydate}</TD>                        <TD>${items.remarks}</TD>                        </TR>                        </C:foreach>

But sometimes our data need to use JS to load, you can no longer use <c:foreach>.

Workaround $.format () method.

2, need to add a hidden template in the JSP now.

3. Get the template, and then populate the placeholder. Placeholder will press {0}{1} ... Sequential padding, which can occur multiple times.

var temp=$.format ($ ("#template1"). Val ()); $ ("#tbody1"). Append (Temp ("QW", "N", "Ererer", "RTRT", " 1212121 "," 555555555 ");//Add Element

jquery uses templates to dynamically add HTML elements, equivalent to the foreach in Jstl

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.