Ember.js Components - param is not passed in action inside a component -


what i'm trying do: author can delete own post.

problem: seems parameter param=this not passed inside components: implemented action removepost in app/components/post-box.js triggers item.deleterecord() item undefined when click delete button. please me.

posts.hbs -> post-box.hbs -> post-box.js

app/templates/posts.hbs

<div class="postscontainer">   <div class="innerpostscontent">     {{#each itemcontroller="post"}}       {{!-- here problem: components, param doesn't --}}       {{post-box user=user body=body date=date isauthor=isauthor view=view action="removepost" param=this session=session}}     {{/each}}   </div> </div> 

app/templates/components/post-box.hbs

<div class="eachpost">   <div class="eachpostcontent" {{action 'showdelete'}}>     <p class="postauthor"><strong>{{user.id}}</strong></p>     <p class="postcontent">{{body}}</p>     <span class="timeposted"><em>{{format-date date}}</em></span>       {{#if isauthor}}            {{!-- part leads next file: app/components/post-box.js --}}         <a class="deletepost" {{action "removepost" this}}>delete</a>        {{/if}}   </div>   {{/view}} </div> 

app/components/post-box.js

export default ember.component.extend({   actions: {     removepost: function(item) {       if(this.get('session.user') && item.get('user') === this.get('session.user')){         item.deleterecord(); // error: uncaught typeerror: undefined not function          item.save();       } else {         console.log("you not post's author");       }     }   } }); 

i'd recommend using controller.model instead of when passing current context in, beside that, name inside component param not this, should using

<a class="deletepost" {{action "removepost" param}}>delete</a>  

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -