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 = Ember.Component.extend({ tagName: 'li', isDisabled: false, attributeBindings: ['isDisabled:disabled'], classBindings: ['isDisabled:MeasureListItemDisabled'], actions: { add: function(measure) { var store = this.get('store'); store.push('OlapApp.AxisModel', { uniqueName: measure.uniqueName, name: measure.name, hierarchyUniqueName: measure.hierarchyUniqueName, type: 'row', isMeasure: true, orderId: 1 }); } } });
and this is error:
Uncaught TypeError: Cannot call method 'push' of undefined MeasureListItemComponent.js:18
is it posible to push record to store from component? why i cant access to store ? my model name is 'AxisModel' and application namespace is 'OlapApp'
It's simple to get access to the store inside a React component – no need to pass the store as a prop or import it, just use the connect function from React Redux, and supply a mapStateToProps function that pulls out the data you need. Then, inside the component, you can pass that data to a function that needs it.
Understanding Context Usage createContext() , called ReactReduxContext . React Redux's <Provider> component uses <ReactReduxContext. Provider> to put the Redux store and the current store state into context, and connect uses <ReactReduxContext. Consumer> to read those values and handle updates.
To access the store in non-component front end code, I used the analogous import (i.e., import {store} from "../../store. js" ) and then used store. getState() and store.
You need to use Store. getState() to get current state of your Store.
Since Ember v1.10, the store can be injected to components using initializers, see: http://emberjs.com/blog/2015/02/07/ember-1-10-0-released.html#toc_injected-properties:
export default Ember.Component.extend({ store: Ember.inject.service() });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With