Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将帮助程序添加到“下划线”模板?_Javascript_Jquery_Underscore.js_Underscore.js Templating - Fatal编程技术网

Javascript 如何将帮助程序添加到“下划线”模板?

Javascript 如何将帮助程序添加到“下划线”模板?,javascript,jquery,underscore.js,underscore.js-templating,Javascript,Jquery,Underscore.js,Underscore.js Templating,我正在尝试将helper函数添加到我的下划线模板中。但我不能这样做。有人能纠正我吗 这是我的tempalate: <script type="text/template" id="table"> <table> <tbody> <tr> <% _.each(obj.titles, function(item){ %>

我正在尝试将helper函数添加到我的
下划线
模板中。但我不能这样做。有人能纠正我吗

这是我的tempalate:

<script type="text/template" id="table">
    <table>
        <tbody>
            <tr>
                <% _.each(obj.titles, function(item){ %>
                    <td><%= item.label %>
                <% }); %>
            </tr>
        </tbody>
    </table>
</script>
但是我根本无法调用我的助手函数

请更新到我的小提琴


它与您的代码配合得很好。您只需使用模板中的函数:

<script type="text/template" id="table">
    <table>
        <tbody>
            <tr>
                <% _.each(obj.titles, function(item){ %>
                    <td><%= item.label %></td>
                <% }); %>
            </tr>
             <tr>
                <% _.each(obj.titles, function(item){ %>
                    <td><%= getProperty(item.label) %></td>
                <% }); %>
            </tr>
        </tbody>
    </table>
 </script>


这是一个有效的提示:

您的模板没有使用
getProperty
,您是否尝试在模板中调用
getProperty
<script type="text/template" id="table">
    <table>
        <tbody>
            <tr>
                <% _.each(obj.titles, function(item){ %>
                    <td><%= item.label %></td>
                <% }); %>
            </tr>
             <tr>
                <% _.each(obj.titles, function(item){ %>
                    <td><%= getProperty(item.label) %></td>
                <% }); %>
            </tr>
        </tbody>
    </table>
 </script>