jquery - 在 jQuery 模板中仅显示前 10 个

标签 jquery jquery-templates wufoo

我们使用 jQuery、jQuery 模板和 Wufoo jQuery API 来显示表单中的数据,使用以下代码:

<div id="people">           
    <ul>
        <script id="attendeeTemplate" type="text/x-jquery-tmpl">
            <li>
                <h4>${Field1}</h4>
                ${Field3} minutes
            </li>
             </script>
    </ul>
</div>

这效果很好,但是我们希望将其限制为仅显示前 10 个条目。现在它正在显示数据库中的每个条目(使用下面的 JavaScript 和 API 排序)。请注意,我们仅尝试显示前 10 名,按分钟数从高到​​低排序。

这是 JavaScript:

<script>
    function processEntries(data) {
        $.each(data.Entries, function(entriesIndex, entriesObject) {
            // Make sure this entry has all the required bits
            if (entriesObject.Field1 && entriesObject.Field3) {
                $("#attendeeTemplate").tmpl(entriesObject).appendTo("#people ul");  
            }
        });
    };

    $.wufooAPI.getEntries({
        "callback"   : processEntries,             // Name of custom function declared above
        "formHash"   : "BLAH",                   // Found by clicking "Code" button from the Form Manager, then the "API Information" button
        "sortID"   : "Field3",                   // Found by clicking "Code" button from the Form Manager, then the "API Information" button
        "sortDirection"   : "DESC",                   // Found by clicking "Code" button from the Form Manager, then the "API Information" button

    });
</script>

任何关于如何将其限制在前 10 名的想法都会非常有帮助!

最佳答案

这应该有效:

data.Entries.slice(0,9); 

关于jquery - 在 jQuery 模板中仅显示前 10 个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10561168/

相关文章:

javascript - 类似于 Wufoo 的 Web 界面(可拖动元素、记住状态)

javascript - jQuery $ ('parent > *' ) 选择器和带有点击委托(delegate)的 iOS

javascript - JQuery mobile 未将用户输入检查项目的样式设置为与列表的其余部分相同

javascript - 如何统计网页中创建的警告框的数量?

jquery-templates - 如何将字符串转换为jquery对象?

jquery - 理解Jquery模板

iphone - 在 Objective C 中将数据发布到 Wufoo 表单

python - Python 中的 Wufoo API 在特定时间后按日期时间排序不起作用

javascript - jQuery 动画数字计数器从零到值 - 当值达到数十万时计数器显示错误值

knockout.js - 使用 knockout 的 jquery 模板内的单选按钮列表