注册 登录
编程论坛 JavaScript论坛

Jtemplate问题 求高手解答~!

Alex1111 发布于 2012-03-28 12:12, 798 次点击
程序代码:
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>jTemplates</title>
</head>
<body>
    <div id="result"></div>
    <div id="foreachResult"></div>
</body>
<script src="http://ajax.
<script src="http://jtemplates.
<BR><script type="text/template" id="foreach">
    <table>
    <thead>
        <tr>
            <td>Index</td>
            <td>ID</td>
            <td>Name</td>
            <td>Age</td>
            <td>Mail</td>
        </tr>
    </thread>
    <tbody>
        {#foreach $T.table as record begin=1}  
        <tr>
            <td>{$T.record$index}</td>  
            <td>{$T.record.id}</td>
            <td>{$T.record.name}</td>
            <td>{$T.record.age}</td>
            <td>{$T.record.mail}</td>
        </tr>
       {#/for}  
    </tbody>
</table>
</script>
<script>
    $(function($) {
        var data = {
            name: 'User list',
            list_id: 6,
            table: [
      { id: 1, name: 'Alex', age: 21, mail: 'Alex@' },
      { id: 2, name: 'Amelie', age: 24, mail: 'amelie@' },
      { id: 3, name: 'Polly', age: 18, mail: 'polly@' },
      { id: 4, name: 'Alice', age: 26, mail: 'alice@' },
      { id: 5, name: 'Martha', age: 25, mail: 'martha@' }
     ]
        };
        var mydata = { name: "Alex", age: "21" };
        $("#result").setTemplate("My name is {$T.name}");

        $("#result").processTemplate(mydata);
        $('#foreachResult').setTemplate($('#foreach').html()).processTemplate(data);
        $('#foreachResult').delegate('td', 'click', function() {
            alert($(this).text());
        });
    });  
</script>
</html>
{#foreach $T.table as record begin=1}中如果把begin去掉的话就不会显示数据了 怎么回事???
4 回复
#2
Alex11112012-03-28 13:50
没人会么?
#3
aspic2012-04-09 15:57
begin=数值,这里指定的是数据从第几条开始吧
#4
aspic2012-04-09 15:59
f._option = {'begin': (RegExp.$2 || 0), 'end': (RegExp.$3 || -1), 'step': (RegExp.$4 || 1), 'extData': '$T'};

代码里面显示,如果不指定值则从第0条开始。。。然后你的数据是从第1条开始的 所以你不指定就显示不出来了
#5
wangsj_20012012-04-11 14:28
学习了
1