-
14 Oct 2011 7:52 AM #1
Unanswered: How do I reference a store from a view in a MVC app?
Unanswered: How do I reference a store from a view in a MVC app?
I have a Panel which has a List of employees. The employees are in store/Employees.js.
view/Employees.js
store/Employees.jsCode:Ext.define('MyApp.view.Employees', { extend: 'Ext.Panel', xtype: 'employeepanel' config: { title: 'Employees', iconCls: 'team', layout: 'card', items: [ { xtype: 'panel', layout: 'fit', items: [ { xtype: 'list', indexBar: true, itemTpl: '<div>{lastName}</div>', store: MyApp.store.Employee } ] } ] }, });
In the config:Code:Ext.define('MyApp.store.Employees', { extend: 'Ext.data.Store', model: 'MyApp.model.Employee', requires: ['MyApp.model.Employee'] data: [ { lastName: 'Smith', firstName: 'Robert'}, { lastName: 'Brown', firstName: 'John'}, { lastName: 'Evans', firstName: 'Mary'} ] } );
Should this be in quotes? Should it be the "id" of the store? Do I need a "requires"?Code:store: MyApp.store.Employee
-
14 Oct 2011 7:56 AM #2Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Haarlem, Netherlands
- Posts
- 1,235
- Vote Rating
- 4
- Answers
- 28
The MVC package automatically assigns id's to stores based on their class name. In your example the following should work:
store: 'Employee'
Remember to add this store in either your Application, a Controller, or as a requires in your View.
-
14 Oct 2011 11:15 AM #3
Thanks but it doesn't work in that nothing is displayed in the list. How can I debug this? Is there a method I can implement to dump the contents of the store? And how do I reference the store from that method?
-
14 Oct 2011 5:07 PM #4
The strange thing is that this code doesn't work:
but this does work:Code:{ xtype: 'list', indexBar: true, itemTpl: '<div>{lastName}</div>', store: 'MyApp.store.Employee' }
Code:{ xtype: 'list', indexBar: true, itemTpl: '<div>{lastName}</div>', store: { model: 'MyApp.model.Employee', data: [ { lastName: 'Brown' }, { lastName: 'Smith' } ] } }
-
15 Oct 2011 1:57 AM #5
@robl,
You are forgetting an "s" after Employee. The store is defined as MyApp.store.Employees but you're referencing it as MyApp.store.Employee. Try this instead :
Code:{ xtype: 'list', indexBar: true, itemTpl: '<div>{lastName}</div>', store: 'Employees' }
-
15 Oct 2011 6:54 AM #6
Unfortunately, that was just a typo in my post and not in my code. I am still looking for a solution. More importantly, I am looking for a way to debug these types of problems. I need to help on what methods I can add to a Component that allow me to print out debug logs before and after the component is rendered (or thereabouts.) The only one I know of is "initialize" I also need to know how to reference objects that are part of a config: i.e. If I have a "list" inside a "panel", how do I get a reference to it so that I can print a debug log with some of it's attributes?
-
17 Oct 2011 10:05 AM #7
Just learning myself
Just learning myself
Check out Tommy's post:
http://www.sencha.com/learn/architec...xt-js-4-part-3
Looks like you want to avoid ref'ing a view from a store if you can. If you need to, add a
<code>
...
stores: ['Employees']
...
</code>
to your Employees view. Then you can do this.getEmployeesStore() for your list.


Reply With Quote

