2017-04-02 57 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

工作,謝謝你們。 –