Git Product home page Git Product logo

Comments (4)

shepherdwind avatar shepherdwind commented on July 20, 2024

你的代码我修改了一下:

var velocity = require('velocity.js');

var str = '#set($js_file = [ ' +
  '"js/app/apww.js"'+
  '])' +
  '#foreach($item in $js_file)' +
  // macros应该是#s,而不是js那样s
  '#s($item)' +
  '#end';

//第二个参数是数据,第三个参数才是macros
var property = velocity.render(str, {}, {

  //函数的s没有带进来
  s: function(s) {
    return s.replace('.js', '');
  }
});

console.log(property)

另外,也许是velocity的版本,你跑一下velocity -v对比一下npm info velocity.js version,我也不知道什么时候升级过了一下。现在是0.3.1了

from velocity.js.

popomore avatar popomore commented on July 20, 2024

这个 s 不是 macro,是一个 java 工具类,真正出问题的是 $stringUtil.substringBefore,我简化成 s 了

from velocity.js.

shepherdwind avatar shepherdwind commented on July 20, 2024

哦,那应该是这样才是$s($item)才是吧,我这边输出对啊。

var velocity = require('velocity.js');

var str = '#set($js_file = [ ' +
  '"js/app/apww.js"'+
  '])' +
  '#foreach($item in $js_file)' +
  '$s($item)' +
  '#end';

var property = velocity.render(str, {
  s: function(s) {
    return s.replace('.js', '');
  }
});

console.log(property)

from velocity.js.

popomore avatar popomore commented on July 20, 2024

恩,这是我的问题

from velocity.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.