Comments (4)
你的代码我修改了一下:
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.
这个 s 不是 macro,是一个 java 工具类,真正出问题的是 $stringUtil.substringBefore
,我简化成 s 了
from velocity.js.
哦,那应该是这样才是$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.
恩,这是我的问题
from velocity.js.
Related Issues (20)
- Dashes in Identifiers HOT 1
- Support format quiet syntax $!{reference}
- String.replace() is not global HOT 2
- Map.remove() is not implemented HOT 2
- String pipe symbol not implemented HOT 1
- Support the $util.qr directive HOT 1
- IE or older browsers not supported!!! HOT 1
- Bug with #set inside #foreach: setting properties on loop variable from foreach doesn't work HOT 1
- TypeError: Cannot read property 'charCodeAt' of undefined HOT 1
- 如何实现webpack的热更新? HOT 2
- String matches does not work HOT 2
- 变量名称是null时报错 HOT 1
- Bug with rendering #foreach and $util.map.copyAndRemoveAllKeys HOT 13
- How to figure out which references in AST are able to be set in context HOT 2
- Support method with arguments HOT 2
- Parse String to Int HOT 2
- ESM module build? HOT 10
- #set with array fails for unknown reason HOT 1
- 无法解析vue中使用element-ui的$message语法 HOT 1
- Date functions not working HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from velocity.js.