PDA

View Full Version : JsonStore fields from remote



Safalext
11 Feb 2010, 2:48 AM
Hi,

I have a JsonStore that gets ID's only and I want to get the values for those ID's from a .net MVC application.

I convert the dates using a local function

{ name: "ExpirationDate", convert: convertDate },But for fields like "AffectedID" I need to call a function that returns the value for the ID.

How can I send "AffectedID"to a function as a parameter so it would retrieve a string value like:

{ name: "AffectedID", mapping: GetValueFrom("AffectedID") },

GetValueFrom(ID) will return a string value from an enumeration type.

Can I have a MVC Controller action result return the result?

Thanks in advance

Safalext
11 Feb 2010, 4:36 AM
Not sure if what im doing is right..
but using a request im trying to achieve this:


function GetValue(v) {
var conn = new Ext.data.Connection();
conn.request({
url: 'test/GetObjectByID',
method: 'GET',
params: { id: v },
success: function (responseObject) {
return responseObject.responseText;
},
failure: function () {
Ext.Msg.alert('Status', 'Something went wrong!');
}
});
}

the error is:

The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.JsonResult GetObjectByID(Int32)'

What am I doing something wrong in sending the id ?

Safalext
11 Feb 2010, 4:44 AM
Seems like this a one way to do, not sure though..

Im, emulating the dateconvert method and used a connection.request function


{ name: "AffectedObject", convert: GetValue },


function GetValue(v) {
var conn = new Ext.data.Connection();
conn.request({
url: 'test/GetObjectByID',
method: 'GET',
params: { id: v },
success: function (responseObject) {
return responseObject.responseText;
},
failure: function () {
Ext.Msg.alert('Status', 'Something went wrong');
}
});
}


Im getting an error:

"The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.JsonResult GetObjectByID(Int32)"

It seems its not sending the parameter to the method..

What am I doing wrong?

Safalext
11 Feb 2010, 4:45 AM
Seems like this a one way to do, not sure though..

Im, emulating the dateconvert method and used a connection.request function


{ name: "AffectedObject", convert: GetValue },

function GetValue(v) {
var conn = new Ext.data.Connection();
conn.request({
url: 'test/GetObjectByID',
method: 'GET',
params: { id: v },
success: function (responseObject) {
return responseObject.responseText;
},
failure: function () {
Ext.Msg.alert('Status', 'Something went wrong');
}
});
}


Im getting an error:

"The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.JsonResult GetObjectByID(Int32)"

It seems its not sending the parameter to the method..

What am I doing wrong?

Safalext
11 Feb 2010, 6:40 AM
Hi again,

I was sending GET instead of POST Now I see the return value is the right one but its just not mapped to the field?

Can you help Please

Safalext
11 Feb 2010, 7:06 AM
I can see the Json results for the Store which is an array [0]

GetValue Request is returning "Club"its Json shows
0 C
1 l
2 u
3 b

Is there a different mapping? why isnt anybody answering?

Safalext
11 Feb 2010, 11:50 PM
Still can't figure this out, value returns either as JSON or HTML but isn't displayed..

When i break on the Request success method it is shown when I continue but not in regular page load..:-/

Safalext
14 Feb 2010, 12:17 AM
Hi,
I'm still not able to get the erturn into the grid:



this.AlertStore = new Ext.data.JsonStore({
url: 'test/getalerts',
root: '',
fields: [{ name: "rule", mapping: "rule.Name" },
{ name: "league", mapping: "league.Name" },
{ name: "ExpirationDate", convert: convertDate },
{ name: "AffectedObject", convert: GetValue },
{ name: "AffectedID"},
{ name: "expectedResult"},
{ name: "Fulfilled"},
{ name: "message", mapping: "message.MessageText" },
{ name: "EventLogID"},
{ name: "AlertStatus"},
{ name: "ID"},
{ name: "OrganizationId"},
{ name: "Name"},
{ name: "RecordOwner"},
{ name: "RecordStatus"},
{ name: "RecordTime"},
{ name: "HasID"}]
});

function GetValue(v) {
var conn = new Ext.data.Connection();
conn.request({
url: "test/GetObjectByID",
method: "POST",
params: { id: v },
scriptTag: true,
success: function (response) {
console.log(response.responseText);
ReturnResult(Ext.decode(response.responseText));
return Ext.decode(response.responseText);
},
failure: function () {
Ext.Msg.alert('Status', 'Something went wrong');
}
});the response code is 200 and isee the correct response but it doesn't appear on the grid..

Why is that?

Safalext
14 Feb 2010, 12:18 AM
Hi,
I'm still not able to get the erturn into the grid:



this.AlertStore = new Ext.data.JsonStore({
url: 'test/getalerts',
root: '',
fields: [{ name: "rule", mapping: "rule.Name" },
{ name: "league", mapping: "league.Name" },
{ name: "ExpirationDate", convert: convertDate },
{ name: "AffectedObject", convert: GetValue },
{ name: "AffectedID"},
{ name: "expectedResult"},
{ name: "Fulfilled"},
{ name: "message", mapping: "message.MessageText" },
{ name: "EventLogID"},
{ name: "AlertStatus"},
{ name: "ID"},
{ name: "OrganizationId"},
{ name: "Name"},
{ name: "RecordOwner"},
{ name: "RecordStatus"},
{ name: "RecordTime"},
{ name: "HasID"}]
});

function GetValue(v) {
var conn = new Ext.data.Connection();
conn.request({
url: "test/GetObjectByID",
method: "POST",
params: { id: v },
scriptTag: true,
success: function (response) {
console.log(response.responseText);
ReturnResult(Ext.decode(response.responseText));
return Ext.decode(response.responseText);
},
failure: function () {
Ext.Msg.alert('Status', 'Something went wrong');
}
});the response code is 200 and isee the correct response but it doesn't appear on the grid..

Why is that?

Safalext
14 Feb 2010, 11:45 PM
Just in-case some poor like me encounters the same problem. Thanks for the help fellas.


The 'convert' property is expecting an immediate return value. Your GetValue function is issuing an asynchronous request and then immediately returning nothing. At some arbitrary point in the future after the request completes the 'success' function is called, but it is no longer connected to the original call so any value it may return is meaningless.
Though you could make it work by replacing the use of Ext.data.Connection with manually constructed synchronous requests, I recommend reconsidering the mechanism by which you are getting this data. Issuing a separate request for every record in your data store is less than optimal.
The best solution is to bring that additional data in on the server side and include it in the response to the store proxy's initial request. If that cannot be done then you can try listening to the store's 'load' event and performing conversion for all loaded records with a single request. Any grids or other views you have reading from the store may have to be configured to display dummy text in place of the missing data until the conversion request completes.