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

当双括号里出现class等会报错 #422

Closed
dntzhang opened this issue Jun 15, 2017 · 3 comments
Closed

当双括号里出现class等会报错 #422

dntzhang opened this issue Jun 15, 2017 · 3 comments

Comments

@dntzhang
Copy link

dntzhang commented Jun 15, 2017

接上一个 issue :#408

{{class}}会报错。class在json中还是蛮常用。

   var html = template.compile(`
        <h1>{{title}}</h1><div>{{class}}</div>
                    <ul>
                        {{each list as value i}}
                        <li onclick="showMe('{{value}}')">索引 {{i + 1}} :{{value}}</li>
                        {{/each}}
                    </ul>
        `)({
         title: '标签',
         list: ['文艺', '博客', '摄影', '电影', '民谣', '旅行', '吉他'],
         class: 'abc'
     });

版本: [email protected]

@aui
Copy link
Collaborator

aui commented Jun 15, 2017

有一个限制:目标输出的变量不能是 javascript 关键字或保留字。

下面都是非法的:

{{var}}
{{a ? class : var}}

解决方案:

模板一级特殊变量可以使用 $data 加下标的方式访问

{{$data['var']}}
{{a ? $data['class'] : $data['var']}}

@dntzhang
Copy link
Author

好。多谢~~~

@laserw9
Copy link

laserw9 commented Jun 15, 2017

原来做了处理的,不错不错

@aui aui closed this as completed Jun 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants