getSelectedGridData()[getSelectedRow()] = eval(response.responseText);
I believe that will work.
Greg
________________________________
From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]
On Behalf Of Joe
Hudson
Sent: Tuesday, April 18, 2006 12:56 PM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails-spinoffs] how to evaluate responseText as an array?
Hello,
I have an array of arrays (used for the seed of a grid component). I am
trying to update the grid at runtime so I have to update the underlying
array.
Using the following code, I get the appropriate response but it is just
a string... how can I convert it to an array? Please see the example
below:
foo = new Ajax.Request(
url,
{
method: ''get'',
parameters: params,
onComplete: function (response) {
alert(response.responseText);
getSelectedGridData()[getSelectedRow()]
response.responseText;
}
});
The response.responseText is "[''value 1'', ''value
2'', ''value 3'']" but the
code I have doesn''t work because it isn''t actually the
array... it is
the string representation of the array. Could anybody help me please?
Thanks.
Joe
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
But a better way to do it is probably to do:
getSelectedGridData()[getSelectedRow()]
response.responseText.replace(/[\[\]\'']/g,'''').split(/\s*,\s*/);
Eval is likely slower than a string split(), but that code would only
work in the case that the values never contained a comma. Anyhoo, just
food for thought, but it may require some tweaking of your server-side
code to make sure no commas end up in the values. The call to replace()
would not be necessary if the server side simply returned: value 1,
value 2, value 3 instead of [''value 1'', ''value
2'', ''value 3''].
Greg
________________________________
From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]
On Behalf Of Joe
Hudson
Sent: Tuesday, April 18, 2006 12:56 PM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails-spinoffs] how to evaluate responseText as an array?
Hello,
I have an array of arrays (used for the seed of a grid component). I am
trying to update the grid at runtime so I have to update the underlying
array.
Using the following code, I get the appropriate response but it is just
a string... how can I convert it to an array? Please see the example
below:
foo = new Ajax.Request(
url,
{
method: ''get'',
parameters: params,
onComplete: function (response) {
alert(response.responseText);
getSelectedGridData()[getSelectedRow()]
response.responseText;
}
});
The response.responseText is "[''value 1'', ''value
2'', ''value 3'']" but the
code I have doesn''t work because it isn''t actually the
array... it is
the string representation of the array. Could anybody help me please?
Thanks.
Joe
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Thanks very much, Greg. That solved my problem.
Joe
_____
From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]
On Behalf Of Gregory
Hill
Sent: Tuesday, April 18, 2006 3:01 PM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: RE: [Rails-spinoffs] how to evaluate responseText as an array?
But a better way to do it is probably to do:
getSelectedGridData()[getSelectedRow()]
response.responseText.replace(/[\[\]\'']/g,'''').split(/\s*,\s*/);
Eval is likely slower than a string split(), but that code would only work
in the case that the values never contained a comma. Anyhoo, just food for
thought, but it may require some tweaking of your server-side code to make
sure no commas end up in the values. The call to replace() would not be
necessary if the server side simply returned: value 1, value 2, value 3
instead of [''value 1'', ''value 2'',
''value 3''].
Greg
_____
From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]
On Behalf Of Joe
Hudson
Sent: Tuesday, April 18, 2006 12:56 PM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails-spinoffs] how to evaluate responseText as an array?
Hello,
I have an array of arrays (used for the seed of a grid component). I am
trying to update the grid at runtime so I have to update the underlying
array.
Using the following code, I get the appropriate response but it is just a
string. how can I convert it to an array? Please see the example below:
foo = new Ajax.Request(
url,
{
method: ''get'',
parameters: params,
onComplete: function (response) {
alert(response.responseText);
getSelectedGridData()[getSelectedRow()]
response.responseText;
}
});
The response.responseText is "[''value 1'', ''value
2'', ''value 3'']" but the
code I have doesn''t work because it isn''t actually the array.
it is the
string representation of the array. Could anybody help me please? Thanks.
Joe
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs