Access store from component

后端 未结 7 784
离开以前
离开以前 2020-12-08 04:40

i have a component and when user click on component it add some value to store,i try to use this way but i get an error :

OlapApp.MeasureListItemComponent =         


        
7条回答
  •  不知归路
    2020-12-08 04:44

    The store can be injected with help of dependency injection.

    Example

    import Ember from 'ember';
    
    export default Ember.Component.extend({
    
      /**
       *
       */
      store: Ember.inject.service(),
    
      /**
       * Initialize the component.
       */
      init() {
        this.initialize();
    
        this._super();
      },
    
      /**
       * Initialize the properties and prerequisites.
       */
      initialize() {
        // Set the component properties
        this.todos().then((data) => {
          this.set('todoEntries', data);
        });
      },
    
      /**
       * Returns the todo entries.
       *
       * @returns {*|Promise|Promise.}
       */
      todos() {
        const store = this.get('store');
    
        return store.findAll('todo');
      },
    
    });
    

提交回复
热议问题