JsRender-在助手中调用助手

时间:2019-02-01 17:12:06

标签: jsrender

是否可以在帮助程序声明中调用帮助程序?

我定义了两个助手:someFunctionAsomeFunctionB。我想用someFunctionB,并且调用内部someFunctionA

我尝试致电someFunctionA()this.someFunctionA()

模板

<span>{{:~someFunctionB(123)}}<span>

JS

$.views.helpers({
    someFunctionA: function(value)
    {
        return value++;
    },
    someFunctionB: function(value)
    {
        new_value = someFunctionA(value);

        return "the value is: " + value;
    }
});

1 个答案:

答案 0 :(得分:1)

你可以

new_value = this.ctxPrm("someFunctionA")(value);

请参见www.jsviews.com/#viewobject@ctxprm

或者您可以简单地进行

functionA() {
    return value++;
}
functionB() {
    new_value = functionA(value);
    return "the value is: " + value;
}
...
$.views.helpers({
    someFunctionA: functionA,
    someFunctionB: functionB
});