Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

link-to action parameters are not working in ember js

Tags:

ember.js

Hi i am very new to ember js. i pass action parameters(id ) on link-to action in template but i did not get the values in my controller.

My Template code as follows:

index.html:

             <script type="text/x-handlebars" data-template-name="search">

             {{#each model.results}}

             // here i pass id value along with action

             {{#link-to 'profile' id action="profileinfo"}}

             </script>

app.js:

          App.SearchController = Ember.ObjectController.extend({

             id: '',

             actions:{
               profileinfo: function(id){

                // Here i access id value like this
               console.log(id);
               var id = this.get('id');})  

when i click on the link action goes to Searchcontroller, but i get id value is empty.I follow some solutions in stack overflow but unfortunately i did not get anything. Please provide some solution

like image 810
vinay kallepalli Avatar asked Apr 03 '14 04:04

vinay kallepalli


1 Answers

I don't get why you're using the {{#link-to}} helper for triggering an action on your controller. Maybe you could simply use the {{action}} helper ?

If you try doing it that way, would it work ?

<button type="button" {{action "profileinfo" id}}>Click me !</button>

From there, your console.log(id); should get your value.

EDIT

Would also work for a <a> tag

<a href="#" {{action "profileinfo" id}}>Click me !</a>
like image 196
Pascal Boutin Avatar answered Nov 09 '22 22:11

Pascal Boutin