-
1 Dec 2012 11:08 AM #1
Answered: Why is my list not loading data?
Answered: Why is my list not loading data?
Could anyone help me out, I just begun using Sencha Touch so this it my first app attempt.
I want to setup a global data store, populate it with a Json array from a variable so the store type should be memory. The bind the store to a list and push the list into view.
I can create and populate the store, the list panel pushes into view but is empty.
I'm pretty sure it's a simple mistake but I can not figure it out, been trying for the last three hours..
Store
ModelPHP Code:Ext.define('Lanetalk.store.Customers', {
extend: 'Ext.data.Store',
config: {
model: 'Lanetalk.model.Customer',
proxy: {
type: 'memory',
reader: {
type: 'json'
}
},
autoLoad: true
}});
ListPHP Code:Ext.define('Lanetalk.model.Customer', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'uuid', type: 'string'},
{name: 'premium', type: 'string'},
{name: 'location', type: 'string'},
{name: 'address', type: 'string'},
{name: 'longitude', type: 'string'},
{name: 'latitude', type: 'string'},
{name: 'company_name', type: 'string'},
{name: 'official_phone', type: 'string'},
{name: 'url', type: 'string'},
{name: 'system', type: 'string'},
{name: 'lanes', type: 'string'},
{name: 'visitors_current', type: 'string'},
{name: 'active_games', type: 'string'},
{name: 'active_uploads', type: 'string'},
{name: 'active', type: 'string'}
]
}});
Method that populates the store and creates the listPHP Code:Ext.define('Lanetalk.view.Customers', {
extend: 'Ext.form.Panel',
xtype: 'customers',
requires: [
'Ext.dataview.List',
'Ext.data.Store',
'Lanetalk.store.Customers'
],
config: {
items: {
xtype: 'list',
itemTpl: '{company_name}',
store: 'Customers'
}
}});
PHP Code:var customersStore = Ext.getStore('Customers');
console.log('Items in Store: '+ customersStore.getCount());
customersStore.removeAll();
Ext.Array.each(record.get('customers'), function(customer, index) {
customersStore.add(customer);
});
customersStore.sync();
this.getCountries().push({
xtype: 'customers'
});
-
Best Answer Posted by ZyBeR
It turned out that the store was working, but the list was not showing the items due to it was inside a panel. When I removed the panel the list worked with no other modifications.
How ever, your suggestions are interesting.
When I create a store and populate it manually (from a local variable), shall I not set any proxy? If so, when is the memory type used?
The record variable is a subset of a json object.
-
2 Dec 2012 2:35 AM #2
The data you have listed on model as such.
{name: 'uuid', type: 'string'},
{name: 'premium', type: 'string'},
{name: 'location', type: 'string'},
{name: 'address', type: 'string'},
{name: 'longitude', type: 'string'},
{name: 'latitude', type: 'string'},
{name: 'company_name', type: 'string'},
{name: 'official_phone', type: 'string'},
{name: 'url', type: 'string'},
{name: 'system', type: 'string'},
{name: 'lanes', type: 'string'},
{name: 'visitors_current', type: 'string'},
{name: 'active_games', type: 'string'},
{name: 'active_uploads', type: 'string'},
{name: 'active', type: 'string'}
this needs to be on the store not model. Your model should only contain {name} and {type}.
Also you don't need proxy in your store. The data is already there. Proxy is only used to retrieve data from another server.
Hope that helps
-
2 Dec 2012 6:48 PM #3
what is 'record'? Are you sure the type of 'customers' field is 'auto'?Code:Ext.Array.each(record.get('customers'), function(customer, index) { customersStore.add(customer); });I write English by translator.
-
3 Dec 2012 5:55 AM #4
It turned out that the store was working, but the list was not showing the items due to it was inside a panel. When I removed the panel the list worked with no other modifications.
How ever, your suggestions are interesting.
When I create a store and populate it manually (from a local variable), shall I not set any proxy? If so, when is the memory type used?
The record variable is a subset of a json object.


Reply With Quote