Set lodash / underscore template settings globally using require.js

后端 未结 3 1485
被撕碎了的回忆
被撕碎了的回忆 2020-12-24 03:54

Is there a way to set the templateSettings for lodash when using RequireJS?

Right now in my main startup I have,

  require([\'lodash\',          


        
3条回答
  •  清歌不尽
    2020-12-24 04:43

    You should pass your _ variable with template settings as function argument or as property in global object (window for browsers or proccess for nodejs).

    _.templateSettings = {
          interpolate: /\{\{(.+?)\}\}/g,
          evaluate: /\{\%(.+?)\%\}/g
    };
    questionView = new QuestionView(_);
    

    Or

    _.templateSettings = {
          interpolate: /\{\{(.+?)\}\}/g,
          evaluate: /\{\%(.+?)\%\}/g
    };
    window._ = _  
    

    First option is better.

提交回复
热议问题