Devon_Britton
20 Jul 2012, 3:57 AM
Hi everyone.
I am new to Sencha Touch and I am using Sencha Architect.
I'm having an issue when loading data from a store.
I have the following nested JSON store (RavenDB):
{
"ID": 3,
"Name": "Sarah Carlson",
"Telephone": "(011) 123 4567",
"Address": "1 Test ave",
"Suburb": "Test",
"City": "Testville",
"Province": "Gauteng",
"Country": "South Africa",
"PostalCode": "0001",
"DeliveryStatus": "Pending",
"Packages": [
{
"ID": 1,
"Name": "Package 1",
"Status": "Pending"
},
{
"ID": 2,
"Name": "Package 2",
"Status": "Pending"
}
]
}
I am populating a list with the data from the store but the problem lies in what happens when you select an item.
I need to take the "Packages" for the selected customer and populate another list on the next page with them, however, I am unable to get any of the Package details. All I get when I load the packages are objects but I cannot pull any data from them.
Here's what I get when I do a console.log(packages):
[
Object
ID: 1
Name: "Package 1"
Status: "Pending"
__proto__: Object
,
Object
ID: 2
Name: "Package 2"
Status: "Pending"
__proto__: Object
Why can't I use the getAt() method to retrieve the information?
My code is as follows.
Shipment Model:
Ext.define('Deliveries.model.Shipment', {
extend: 'Ext.data.Model',
uses: [
'Deliveries.model.Package'
],
config: {
fields: [
{
name: 'ID',
type: 'int'
},
{
name: 'Name',
type: 'string'
},
{
name: 'Telephone',
type: 'string'
},
{
name: 'Address',
type: 'string'
},
{
name: 'Suburb',
type: 'string'
},
{
name: 'City',
type: 'string'
},
{
name: 'Province',
type: 'string'
},
{
name: 'Country',
type: 'string'
},
{
name: 'PostalCode',
type: 'string'
},
{
name: 'DeliveryStatus',
type: 'string'
},
{
name: 'Packages'
}
],
hasMany: {
associationKey: 'Packages',
model: 'Deliveries.model.Package'
}
}
});
Package Model:
Ext.define('Deliveries.model.Package', {
extend: 'Ext.data.Model',
uses: [
'Deliveries.model.Shipment'
],
config: {
fields: [
{
allowNull: false,
name: 'ID',
type: 'int'
},
{
name: 'Name'
},
{
name: 'Status'
}
],
belongsTo: {
model: 'Deliveries.model.Shipment'
}
}
});
Controller:
Ext.define('Deliveries.controller.CustomerController', {
extend: 'Ext.app.Controller',
config: {
refs: {
dataList: '#dataList',
mainNav: '#mainNav',
packageList: '#packageList'
},
control: {
"#dataList": {
itemtap: 'onListItemTap'
}
}
},
onListItemTap: function(dataview, index, target, record, e, options) {
var me = this, info, details;
if (record) {
details = Ext.create('Deliveries.view.DetailsContainer', {
title: record.get('Name')
});
info = details.child('#details');
info.setData(record.data);
var packages = record.get('Packages');
var packageList = details.child('#packageList');
packageList.setData(packages);
me.getMainNav().push(details);
}
}
});
Your help is greatly appreciated!!
Regards,
Devon Britton.
I am new to Sencha Touch and I am using Sencha Architect.
I'm having an issue when loading data from a store.
I have the following nested JSON store (RavenDB):
{
"ID": 3,
"Name": "Sarah Carlson",
"Telephone": "(011) 123 4567",
"Address": "1 Test ave",
"Suburb": "Test",
"City": "Testville",
"Province": "Gauteng",
"Country": "South Africa",
"PostalCode": "0001",
"DeliveryStatus": "Pending",
"Packages": [
{
"ID": 1,
"Name": "Package 1",
"Status": "Pending"
},
{
"ID": 2,
"Name": "Package 2",
"Status": "Pending"
}
]
}
I am populating a list with the data from the store but the problem lies in what happens when you select an item.
I need to take the "Packages" for the selected customer and populate another list on the next page with them, however, I am unable to get any of the Package details. All I get when I load the packages are objects but I cannot pull any data from them.
Here's what I get when I do a console.log(packages):
[
Object
ID: 1
Name: "Package 1"
Status: "Pending"
__proto__: Object
,
Object
ID: 2
Name: "Package 2"
Status: "Pending"
__proto__: Object
Why can't I use the getAt() method to retrieve the information?
My code is as follows.
Shipment Model:
Ext.define('Deliveries.model.Shipment', {
extend: 'Ext.data.Model',
uses: [
'Deliveries.model.Package'
],
config: {
fields: [
{
name: 'ID',
type: 'int'
},
{
name: 'Name',
type: 'string'
},
{
name: 'Telephone',
type: 'string'
},
{
name: 'Address',
type: 'string'
},
{
name: 'Suburb',
type: 'string'
},
{
name: 'City',
type: 'string'
},
{
name: 'Province',
type: 'string'
},
{
name: 'Country',
type: 'string'
},
{
name: 'PostalCode',
type: 'string'
},
{
name: 'DeliveryStatus',
type: 'string'
},
{
name: 'Packages'
}
],
hasMany: {
associationKey: 'Packages',
model: 'Deliveries.model.Package'
}
}
});
Package Model:
Ext.define('Deliveries.model.Package', {
extend: 'Ext.data.Model',
uses: [
'Deliveries.model.Shipment'
],
config: {
fields: [
{
allowNull: false,
name: 'ID',
type: 'int'
},
{
name: 'Name'
},
{
name: 'Status'
}
],
belongsTo: {
model: 'Deliveries.model.Shipment'
}
}
});
Controller:
Ext.define('Deliveries.controller.CustomerController', {
extend: 'Ext.app.Controller',
config: {
refs: {
dataList: '#dataList',
mainNav: '#mainNav',
packageList: '#packageList'
},
control: {
"#dataList": {
itemtap: 'onListItemTap'
}
}
},
onListItemTap: function(dataview, index, target, record, e, options) {
var me = this, info, details;
if (record) {
details = Ext.create('Deliveries.view.DetailsContainer', {
title: record.get('Name')
});
info = details.child('#details');
info.setData(record.data);
var packages = record.get('Packages');
var packageList = details.child('#packageList');
packageList.setData(packages);
me.getMainNav().push(details);
}
}
});
Your help is greatly appreciated!!
Regards,
Devon Britton.