开发者

jQuery tmpl plugin

The most annoying thing about tmpl is that you cant replace ${n} inside <> such as

<a href="details/?id=${id}">${name}</a> 

the ${id} wouldnt get replaced..

Any ideas how to do that without having to use the <script> tags, cause that isnt a good way to do it.

or even how to check a checkbox..

My template looks like this

<table id="lvList" class="grid1">
    <tr>
        <th>Name</th>
        <th>Number</th>
        <th>Type</th>
        <th>Account Manager</th>
    </tr>
    <!-- itemtemplate -->
    <tr>
        <td>{{html $item.href('details/?id=$id')}}</td>
        <td>${id}</td>
        <td>${type}</td>
        <td>${accmgr}</td>
    </tr>
    <!-- itemtemplate -->
</table>

if you want to know how I got the template from the table, y开发者_StackOverflow社区ou can see this post ItemTemplate

Using that template, this is what I came up with

var items = $.tmpl(this.itemtemplate, data, {
    href: function (url) {
        for (i in this.data)
        { url = url.replace("$" + i, this.data[i]); }
        return "<a href=\"" + url + "\">" + this.data["name"] + "</a>";
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜