最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - access object property in handlebar contains '.' - Stack Overflow

programmeradmin2浏览0评论

I am getting data from service in which array of objects are ing like below:-

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

I have used handlebars templating to parse this data like below:-

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

In the above I am not able to access the property('s.no'). In vanilla JavaScript we can access it like this['s.no'] but in handlebars it's not working.

I am getting data from service in which array of objects are ing like below:-

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

I have used handlebars templating to parse this data like below:-

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

In the above I am not able to access the property('s.no'). In vanilla JavaScript we can access it like this['s.no'] but in handlebars it's not working.

Share Improve this question edited Apr 2, 2017 at 13:42 user663031 asked Apr 2, 2017 at 13:32 Inderjeet Singh AhujaInderjeet Singh Ahuja 1943 silver badges13 bronze badges 1
  • 1 {{this.[s.no]}} or {{this.["s.no"]}} try these two. – Irfan Ali Commented Apr 2, 2017 at 13:40
Add a ment  | 

1 Answer 1

Reset to default 4

You need to use special [] notation for properties that are not valid handlebar identifiers. Demo.

{{#each this}}
   <div>
      <span>{{this.[s.no]}}</span>
      <h2>{{this.title}}</h2>
   </div>
{{/each}}
发布评论

评论列表(0)

  1. 暂无评论