mardi 19 avril 2016

Is there any way that I can use ember-data way instead select2?

When I did not use Ember-data, my select2 component like:

import Ember from 'ember';

export default Ember.TextField.extend({
  didInsertElement() {
    var _this = this;
    this.$().select2({
      placeholder: "waiting...",
      minimumInputLength: 1,
      ajax: {
        url: "/api/fitting_items/select_search",
        dataType: 'json',
        quietMillis: 250,
        data(term, page) {
          return {
            q: term,
            stock_type: _this.get('stockType'),
            stock_id: _this.get('stockId')
          }
        },
        results(data, page) {
          return {
            results: data.fitting_items
          }
        },
        cache: true,
      }
    });
  },

  willDestroyElement() {
    this.$().select2('destroy');
  }
})

ember-simple-auth 0.7.3

But I update my project now, I use

DEBUG: -------------------------------
DEBUG: Ember             : 2.4.3
DEBUG: Ember Data        : 2.4.3+a3e2521f85
DEBUG: jQuery            : 2.2.2
DEBUG: Ember Simple Auth : 1.0.0
DEBUG: -------------------------------

And the ember-data use json-api, so my select2 component has some problem.

  1. If I use select2 ajax, I must set token in the header. Because Ember Simple Auth : 1.0.0 must set token by myself if I set custom ajax requet.

  2. I think if I use select2 ajax is not ember data way. It maybe use this.store.query('fittingItem', params) will better.

  3. If I do not use select2, I write a component like select2 is too difficult for me.

So to sum up, I should use what kind of method to solve this problem is better? Thanks.




Aucun commentaire:

Enregistrer un commentaire