PDA

View Full Version : Could I use object property as the successProperty in JsonReader?



bryanevil
17 Jun 2010, 1:11 AM
Hi all

I am in extreme headache here. the successProperty in JsonReader, could I have an json object property assign to the successProperty ? The reason is that .net web service always wiped the json message into the "d" object. for example:

{"d":{"success":true}}



var companyinfoReader = new Ext.data.JsonReader({
totalProperty: 'total',
successProperty: 'success',
idProperty: 'ID',
root: 'd',
messageProperty: 'message',
// map to MonthlyReportDTO
fields: ['CompanyName', 'ID']

});

Bryan

bryanevil
17 Jun 2010, 6:26 AM
still looking for some help please

Animal
17 Jun 2010, 6:44 AM
d.success

bryanevil
17 Jun 2010, 5:10 PM
d.success

Thanks for your supporting. However I still get the red mark at the top-left corner after save.

this is the response from server

{"d":{"success":true}}

This is how I setup my store:


var companyinfoProxy = new Ext.data.HttpProxy({
api:{
// Call web service method using GET syntax
read: '../WebServices/Account/CompanyService.asmx/GetAll',
create: '../WebServices/Account/CompanyService.asmx/Add',
update: '../WebServices/Account/CompanyService.asmx/Update',
destroy: '../WebServices/Account/CompanyService.asmx/Delete'},
// Ask for Json response
headers: { 'Content-type': 'application/json' }
});
var companyinfoReader = new Ext.data.JsonReader({
totalProperty: 'total',
successProperty: 'd.success',
idProperty: 'ID',
root: 'd',
messageProperty: 'message',
// map to MonthlyReportDTO
fields: ['CompanyName', 'ID']

});
var companyinfoWriter = new Ext.data.JsonWriter({
encode: false,
writeAllFields: true
});
var CompanyInfoJsonStore = new Ext.data.Store({
// Load data at once
autoLoad: true,
// Override default http proxy settings
proxy: companyinfoProxy,
reader: companyinfoReader,
writer: companyinfoWriter,
autoSave:false
});
I was following this example all along - http://www.sencha.com/deploy/dev/examples/writer/writer.html

Their server response after save is like this:
{"success":true,"message":"Updated record","data":{"id":4,"first":"Barney","last":"Rubble","email":"[email protected]"}}

i also return true for the success property , why i still get the red corner?

Animal
17 Jun 2010, 9:10 PM
You need to add an exception listener to that Store.

The "red mark" means you have uncommitted changes because the save failed.

That response has no "d" does it? That response has root "data"

bryanevil
17 Jun 2010, 9:37 PM
You need to add an exception listener to that Store.

Is this necessary to make this work?



The "red mark" means you have uncommitted changes because the save failed.

I am sure the save was successful. After refresh the hold page, the saved record was updated.





That response has no "d" does it? That response has root "data"

Sorry for the confusion. This is my server response to extjs after hit "save": {"d":{"success":true}}. So I do as you said and setup

successProperty: 'd.success'

Animal
17 Jun 2010, 11:32 PM
Add an exception listener.

A huge part of software engineering is handling the times when things go wrong.

You are just ignoring that.

bryanevil
20 Jun 2010, 8:00 PM
Add an exception listener.

A huge part of software engineering is handling the times when things go wrong.

You are just ignoring that.

Hi Animal

Thanks for your advance. However, I still facing a problem.

After I add listeners to my DataProxy,my edit and delete actions does not show the read corner anymore after save, except Create action still show the red corner. beforeWrite, Post, and Write work correctly. Could it be because I left one field - "ID" empty? ID is generate at my db server.

This is my field setup:


var CompanyColomn = [
{ header: 'ID', width: 200, sortable: true, dataIndex: 'ID', allowBlank:true},
{ id: 'CompanyName', header: 'Company Name', width: 400, sortable: true, dataIndex: 'CompanyName', editor: new Ext.form.TextField() }

];



This is my listener code:


Ext.data.DataProxy.on('beforewrite', function(companyinfoProxy, action) {
console.log('beforewrite: ', action);
});

// Listen to "write" event fired by all proxies
Ext.data.DataProxy.on('write', function(companyinfoProxy, action, data, res, rs) {
console.info('write: ', action);
});

// Listen to "exception" event fired by all proxies
Ext.data.DataProxy.on('exception', function(companyinfoProxy, type, action) {
console.error(type + action + ' exception');
});

mankz
20 Jun 2010, 10:25 PM
After creating a new record, your server needs to return back all the record fields including the newly generated Id. Check out this example:

http://www.sencha.com/deploy/dev/examples/writer/writer.html and create a record, you'll see the server responds with:


{"success":true,"message":"Created record","data":{"email":"[email protected]","first":"asf","last":"db","id":10}}

bryanevil
20 Jun 2010, 10:49 PM
After creating a new record, your server needs to return back all the record fields including the newly generated Id. Check out this example:

http://www.sencha.com/deploy/dev/examples/writer/writer.html and create a record, you'll see the server responds with:


{"success":true,"message":"Created record","data":{"email":"[email protected]","first":"asf","last":"db","id":10}}


Thank you for your quick reply. I understand now.