Ole Henrik Oftedal
Posts: 0
Joined: Thu Apr 19, 2012 4:52 pm

How to access the "underlying" data(array) of a component

Hi!

If you use a service, and you put the result in a mobilegrid og mobilelist you can get many lines/records when the data comes from a JSON array. Sometimes you might also let the user edit the displayed data so that you can send the modified data back to the database.

I come to think of the stringify function. I know the code here is wrong, but I want to do the similar thing:
var myObject = Tiggr("mobilegrid13").data;
var p = JSON.stringify(myObject); //p could here be a parameter to a service
alert(p); //says of course "not defined"

Better explained: I will let the user edit the data. Then when he/she hits the update button, I want to stringify the value of all the text input components and then send the string to a backend service responsible to post the edited data back to the database.

What is the simplest way of stringify the underlying array? Is this complicated? Do I have to make a loop and iterate through all the lines/records?

Any examples?

best regards

Ole Henrik Oftedal
Timeflex Systemer AS
http://www.timeflex.no
http://www.timeflex.com

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

How to access the "underlying" data(array) of a component

You can get to response data via the jqXHR object (data).

http://api.jquery.com/jQuery.ajax/

You can use success or complete events when defining a service.

Ole Henrik Oftedal
Posts: 0
Joined: Thu Apr 19, 2012 4:52 pm

How to access the "underlying" data(array) of a component

Yes, I know that. Tiggzi uses this data to populate my text input fields.

var m = JSON.stringify(jqXHR.responseText);
alert (m);

works very well from the OnComplete event for the service.

But I cannot access this data in this way from a button on the form.

I could save the data to a local variable but I don't want a copy. Instead I need a pointer or something like that so I can read out again the user modified data.

Maybe this is not possible and I have to make some sort of loop and reading the underlying HTMLs. But I'm not very strong in this area and hoping that there were some easier way out. Maybe there is some example code out there. This could be interesting for many people because it is very general:

  1. Call a service and populate some input controls in a array or mobile list. (You cannot determine the number of record in advance so you need a grid or mobile list)

  2. After modify, save back the data.

    Ole

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

How to access the "underlying" data(array) of a component

It's probably better to save a copy of the data, and then work with it. I think reading the HTMLs could be pretty slow.

Return to “Issues”