javascript - Emberjs pass parameter from template to function -


i have simple foreach loop:

{{#each app.userc.companies}}     <button class="btn btn-inverse btn-huge" {{action setcompany target="app.userc"}}>{{this.name}}</button> {{/each}} 

"companies" element have 2 elements: name , id

when click on button want know "this.id" clicked? how achieve this? tried:

setcompany: function(e){     console.log($(e.target).data(...)); //output: <script id='metamorph-4-start' type='text/x-placeholder'></script>4ff2f79461d69a9811000001<script id='metamorph-4-end' type='text/x-placeholder'></script> } 

but pretty useless , bet not way things done in ember

the jquery click event given context handlebars when triggered. default current view context, can pass in whatever like.

{{#each app.userc.companies}}   <button class="btn btn-inverse btn-huge" {{action setcompany target="app.userc" context="this"}}>{{this.name}}</button> {{/each}}  setcompany: function(event){   var company = event.context } 

you can check out api here, 'specifying context' section.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -