jquery - 错误 : view. hlp(...) 不是 jsrender 中的函数

标签 jquery html templates if-statement jsrender

我正在使用 jsrender 在网格中映射模板。如果条件如下,我正在调用 jsrender 内部的方法,

@section scripts{
    $.views.helpers({
        isMobile: function () {
            return ("@IsMobileDevice" == "False" && (window.innerWidth < 1200));
        }
    });
}
<script type="text/x-jsrender">
    {{if ~isMobile()}}
        <li class="show">Show</li>
    {{/if}}
</script>

但是我收到错误:

view.hlp(...) is not a function.

这里出了什么问题?

最佳答案

我也遇到过类似的问题,我的帮助程序方法中的错误是我在初始化之前调用了我的帮助程序方法。请参阅下面的示例

代码错误

<script type="text/x-jsrender">
{{if ~isMobile()}}
    <li class="show">Show</li>
{{/if}}

 $.views.helpers({
    isMobile: function () {
        return ("@IsMobileDevice" == "False" && (window.innerWidth < 1200));
    }
});
</script>

正确的代码

<script type="text/x-jsrender">
$.views.helpers({
    isMobile: function () {
        return ("@IsMobileDevice" == "False" && (window.innerWidth < 1200));
    }
});
{{if ~isMobile()}}
    <li class="show">Show</li>
{{/if}}
</script>

希望这会有所帮助

关于jquery - 错误 : view. hlp(...) 不是 jsrender 中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37110106/

相关文章:

javascript - jQuery:在 DOM 注入(inject)后选择元素(当元素未知时)

html - 如何在移动屏幕上增加我的 slider 宽度

javascript - 在不破坏子级的情况下更改父级 <li> 的文本

c++ - 为什么 std::bind() 在这种情况下不适用于常量?

php - Symfony2 : Session Global variable in PHP template

javascript - HTML5 phonegap webapp 在 safari 或其他原生应用程序中打开链接

javascript - 自动填充多个字段的 jQuery 库

javascript - 在 Firefox 中有效但在 IE 中无效的 jQuery

html - 为什么我的输入不适合 div?

c++ - 继承函数的重载解决方案