dimanche 31 mai 2015

how to add event for drop-down component to change subdomain by selected item

i use pod structure with ember cli. i have a 'drop-down' component.

in my drop-down.js component:

import Ember from 'ember';
var component = Ember.Component.extend({
tagName: '', //remove extra div wrapper.
valueKey: 'id',
textKey: 'text',
options: [],
value: null,
defaultText: 'select...',
selected: function () {
var valueKey = this.get('valueKey');
var textKey = this.get('textKey');
var defaultText = this.get('defaultText');
var fallbackOption = {};
fallbackOption[valueKey] = 0;
fallbackOption[textKey] = defaultText;

if (Ember.isEmpty(this.get('value'))) {
  return fallbackOption;
}

var selected = this.get('options').findProperty(valueKey,this.get('value'));

return selected ? selected : fallbackOption;
}.property('options', 'value'),
 actions: {
 select(option) {
  var valueKey = this.get('valueKey');
  this.set('value', option[valueKey]);
  }
  }
});

export default component;

i have used this component in index to load countries.

in template.hbs for index :

 <div class="col-lg-3 col-md-3 col-sm-3 col-xs-6 input-padding">
              {{drop-down options=model.countries
              value=country
              valueKey=valueKey
              textKey=textKey
              defaultText=defaultText}}
            </div>

i want to add change event to countries dropdown, that it must change subdomain by country. for example, when i select Iran, its event causes my subdomain changes to 'Iran.site.com. how can i add this event? and where should i add it ?thanks




Aucun commentaire:

Enregistrer un commentaire