2017-04-02 67 views
0

我从服务中获取数据,其中对象的阵列来象下面这样: -手柄栏中的访问对象属性包含'。'

[{ 
     title : 'Tilte 1', 
     s.no : 1 
    }, 
    { 
     title : 'Tilte 2', 
     s.no : 2 
    } 
    ] 

我已经使用车把模板解析像下面这样的数据: -

{{#each this}} 
    <div> 
     <span>{{this.s.no}}</span> 
     <h2>{{this.title}}</h2> 
    </div> 
{{/each}} 

在上述我我无法访问该属性('s.no')。在香草JavaScript中,我们可以像这样访问['s.no'],但是在手柄中它不起作用。

+0

{{this。[s.no]}}或{{this。[“s.no”]}}试试这两个。 –

回答

0

对于无效的车把标识符,您需要使用特殊的[]符号。 Demo

{{#each this}} 
    <div> 
     <span>{{this.[s.no]}}</span> 
     <h2>{{this.title}}</h2> 
    </div> 
{{/each}} 
+0

只是好奇 - 这不需要是'this。['s.no']'? – 2017-04-02 13:41:39

+0

@torazaburo Nope –

+0

工作,谢谢你们。 –