Devon_Britton
24 Jul 2012, 3:23 AM
Hi everyone.
I'm trying to take a record pulled form a nested JSON document, edit it and then save the changes back to my ravenDB store.
So I've managed to pull all the data that I need and iterate through each record to change the status.
The problem is that I'm getting the following error when I try sync to update the store.:
Uncaught Error: [ERROR][Ext.data.proxy.Server#create] JsonP proxies can only be used to read data.
Here's the code for the "Save" button controller. The Store, Model and Proxy Code is below that, along with the JSON document.
Your help is greatly appreciated!!!
var me = this, list = me.getPackageList(), store = me.getDataList().getStore(), details = me.getDetails();
var customer = details.getData();
var cId = customer.ID;
var i = store.findExact('ID', cId);
var packages = store.getAt(i).get('Packages');
for (var a = 0; a < packages.length; a++) {
id = packages[a].ID;
var select = Ext.get('option'+id).dom;
if (select) {
for (var j = 0; j < select.options.length; j++) {
if (select.options[j].selected) {
packages[a].set('Status', select.options[j].value);
}
}
}
}
store.sync();
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',
type: 'auto'
}
],
hasMany: {
associationKey: 'Packages',
model: 'Deliveries.model.Package'
}
}
});
Store:
Ext.define('Deliveries.store.RavenDBStore', {
extend: 'Ext.data.Store',
alias: 'store.ravendb',
requires: [
'Deliveries.model.Shipment'
],
config: {
autoLoad: true,
model: 'Deliveries.model.Shipment',
storeId: 'RavenDBStore',
proxy: {
type: 'jsonp',
url: 'http://localhost:8080/databases/Shipping/docs',
callbackKey: 'jsonp',
reader: {
type: 'json',
rootProperty: 'Shipments'
}
}
}
});
JSON:
{
"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'm trying to take a record pulled form a nested JSON document, edit it and then save the changes back to my ravenDB store.
So I've managed to pull all the data that I need and iterate through each record to change the status.
The problem is that I'm getting the following error when I try sync to update the store.:
Uncaught Error: [ERROR][Ext.data.proxy.Server#create] JsonP proxies can only be used to read data.
Here's the code for the "Save" button controller. The Store, Model and Proxy Code is below that, along with the JSON document.
Your help is greatly appreciated!!!
var me = this, list = me.getPackageList(), store = me.getDataList().getStore(), details = me.getDetails();
var customer = details.getData();
var cId = customer.ID;
var i = store.findExact('ID', cId);
var packages = store.getAt(i).get('Packages');
for (var a = 0; a < packages.length; a++) {
id = packages[a].ID;
var select = Ext.get('option'+id).dom;
if (select) {
for (var j = 0; j < select.options.length; j++) {
if (select.options[j].selected) {
packages[a].set('Status', select.options[j].value);
}
}
}
}
store.sync();
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',
type: 'auto'
}
],
hasMany: {
associationKey: 'Packages',
model: 'Deliveries.model.Package'
}
}
});
Store:
Ext.define('Deliveries.store.RavenDBStore', {
extend: 'Ext.data.Store',
alias: 'store.ravendb',
requires: [
'Deliveries.model.Shipment'
],
config: {
autoLoad: true,
model: 'Deliveries.model.Shipment',
storeId: 'RavenDBStore',
proxy: {
type: 'jsonp',
url: 'http://localhost:8080/databases/Shipping/docs',
callbackKey: 'jsonp',
reader: {
type: 'json',
rootProperty: 'Shipments'
}
}
}
});
JSON:
{
"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"
}
]
}