Git Product home page Git Product logo

Comments (13)

shepherdwind avatar shepherdwind commented on July 20, 2024

这个java的foreach循环是通过一个方法来获取对象的key为一个数组,具体有哪些方法我也不确定,我所知道的是keySetentrySet这个方法我就不知道了,没有文档说明哪些方法是可用的。

我后面会提供一个接口,可以自己配置这样的方法吧,entrySet或者keySet

from velocity.js.

popomore avatar popomore commented on July 20, 2024

返回的是 Map,可以看下 API 文档

http://docs.oracle.com/javase/6/docs/api/java/util/Map.html

期待

from velocity.js.

shepherdwind avatar shepherdwind commented on July 20, 2024

http://git.shepherdwind.com/velocity.js/runner/tests.html?grep=Compile%20Loops%20%23foreach%20with%20map%20entrySet 已经增加entrySet支持,前面链接是测试用例。不过暂时没有提交到npm上,github上已经同步。

from velocity.js.

popomore avatar popomore commented on July 20, 2024

谢谢

from velocity.js.

popomore avatar popomore commented on July 20, 2024

还是上面的例子

$item.key = <script charset="utf-8" src="$staticServer.getURI("/$item.value")"></script>

$item.value 未解析

var property = velocity.render(data, {
  assetsServer: {
    getURI: function(str) {
      return 'http://assets.alipay.net' + str;
    }
  }
});

from velocity.js.

shepherdwind avatar shepherdwind commented on July 20, 2024

这个确实是我的一个bug,因为getXXX的方法,都会直接去读取XXX属性。

from velocity.js.

shepherdwind avatar shepherdwind commented on July 20, 2024

我已经更新了测试用例http://git.shepherdwind.com/velocity.js/runner/tests.html?grep=Compile%20Loops%20%23foreach%20with%20map%20entrySet ,和你的例子一模一样了。你可以再试一下。

另外,给我提bug ,我得感谢你帮我测试才对,呵呵。

from velocity.js.

popomore avatar popomore commented on July 20, 2024

报告,还是有问题。不支持 ${item.value}$!{item.value}

from velocity.js.

shepherdwind avatar shepherdwind commented on July 20, 2024

https://github.com/shepherdwind/velocity.js#string 这个问题是已知的。因为vm对字符串的解析,如果是双引号,
类似于php,比较靠谱的方案是重新调用Parser解析字符串,不过,最初考虑到需要在浏览器端跑,所以双引号字符串
使用正则,匹配最简单的变量形式,你提出的这两者不支持。

不过,如果是在node跑的话,性能问题不大,对待浏览器和node还是的分开。

在 2012-12-19,下午6:20,Haoliang Gao [email protected] 写道:

报告,还是有问题。不支持 ${item.value} 或 $!{item.value}


Reply to this email directly or view it on GitHub.

from velocity.js.

popomore avatar popomore commented on July 20, 2024

那我觉得可以分开处理,不过浏览器真正的使用场景应该不多吧。

from velocity.js.

popomore avatar popomore commented on July 20, 2024

还有一种场景

#set($js_file = {
    "js_arale":"build/js/arale.js?t=$!{timestamp}",
    "js_ma_template":"build/js/ma/template.js?t=20110608",
    "js_pa_pa":"build/js/pa/pa.js?t=20110608",
    "js_swiff":"build/js/app/swiff.js?t=20110608",
    "js_alieditControl":"build/js/pa/alieditcontrol-update.js?t=20110608"
})

#foreach($item in $js_file.entrySet())
    $item.key = <script charset="utf-8" src="$staticServer.getURI("/$item.value")"></script>
#end 

在 set 的时候定义 timestamp,如果通过两次 parse 是否也能搞定?

from velocity.js.

shepherdwind avatar shepherdwind commented on July 20, 2024

这种场景和前面的一样,最终都是对双引号的字符串数值。
在 2012-12-20 上午12:28,"Haoliang Gao" [email protected]写道:

还有一种场景

#set($js_file = {
"js_arale":"build/js/arale.js?t=$!{timestamp}",
"js_ma_template":"build/js/ma/template.js?t=20110608",
"js_pa_pa":"build/js/pa/pa.js?t=20110608",
"js_swiff":"build/js/app/swiff.js?t=20110608",
"js_alieditControl":"build/js/pa/alieditcontrol-update.js?t=20110608"
})

#foreach($item in $js_file.entrySet())
$item.key = <script charset="utf-8" src="$staticServer.getURI("/$item.value")"></script>
#end

在 set 的时候定义 timestamp,如果通过两次 parse 是否也能搞定?


Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-11536520.

from velocity.js.

shepherdwind avatar shepherdwind commented on July 20, 2024

在node环境下,增加 https://github.com/shepherdwind/velocity.js/blob/master/src/velocity.js#L6

Compile.Parser = Parser;

https://github.com/shepherdwind/velocity.js/blob/master/src/compile/literal.js#L108 重复执行Parse。已经发布到github上

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.