Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

过滤器参数为对象属性时报错 #430

Open
conechan opened this issue Jun 21, 2017 · 2 comments
Open

过滤器参数为对象属性时报错 #430

conechan opened this issue Jun 21, 2017 · 2 comments
Labels

Comments

@conechan
Copy link

重现 DEMO:

template-helper.js

var runtime = require('art-template/lib/runtime');

runtime.test = function (v1, v2) {
  return v2;
}

index.js

var TplA = require('tpl/a/a.tpl');

var data = { list: [{ time: 1446175992278 }, { time: 1446176021568 }] };

require('tpl/template-helpers');

$('.js-desc').html(TplA(data));

a.tpl

{{each list as item}}
  <li>{{item.time | test: item.time}}</li>
{{/each}}

报错信息:

    4|         {{each list as item}}
    5|         <li><a href="http://www.qq.com">{{item.time | dateFormat:'yyyy-MM-dd hh:mm:ss'}}</a></li>
 >> 6|         <li>{{item.time | test: item.time}}</li>
    7|         {{/each}}
    8|     </ul>
    9| </div>

CompileError: Unexpected token .
   generated: $$out+=$escape($imports.test(item.time,item,.,time))

art-template 版本:4.11.0

环境版本:浏览器

@aui aui added the bug label Jun 21, 2017
@aui
Copy link
Collaborator

aui commented Jun 22, 2017

过滤器参数不支持使用 js 表达式,后续会改进。临时解决方案

{{each list as item}}
  {{set time = item.time}}
  <li>{{item.time | test: time}}</li>
{{/each}}

@conechan
Copy link
Author

嗯,我们用 set 变量来临时解决了。

我们在迁移到新版 art-template 时发现这个问题,旧版应该是支持 js 表达式的。

谢谢了。

aui added a commit that referenced this issue Jun 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants