Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call an ember component action from within the component

Tags:

ember.js

I am creating a component to wrap the select2 select box. The code is below:

App.FixedSelectComponent = Ember.Component.extend({
  actions: {
    change: function(value) {
      this.set('selectedValue',value);
    }
  },

didInsertElement : function(){
  this.$("#select1").select2().on("change", function(e) {
      if ($.isArray(e.val)) {
          $.each(e.val, function(index,value) {
              console.log("multiple:",value.split('>')[2].split('<')[0]);
             // send to change
          });             
      } else {
          console.log("single:",e.val.split('>')[2].split('<')[0]);  
          // send to change
      }
    });
  },

  willDestroyElement : function() {
    this.$("#select1").select2('destroy');
},

});

however, what I am stuck at is how to send the data that I've got in the on("change") event to the action:change that I've defined , or if I can set the selectedValue property itself in the on("change") event

"this" isn't the component at the "// send to change" lines - how / where do I get the reference to the component itself at this point ?

basically what I am trying to achieve is to get the data passed to the "change" event of select2 into my selectedValue property

thanks

like image 795
jmls Avatar asked Sep 21 '13 08:09

jmls


1 Answers

You can use Component.send('actionName').

I found it in Ember's documentation.

like image 137
Lacek Avatar answered Oct 05 '22 12:10

Lacek