Page 3 of 3

Stringify JSON parsing data and finding data saved in JSON

Posted: Sat Apr 04, 2015 7:19 am
by M&M

generally the way I do that is to inspect the element using browser tools, and then style that element or class in my CSS file

There are quite a number of online css editors that let you create css for backgrounds, gradients, text, shadows etc


Stringify JSON parsing data and finding data saved in JSON

Posted: Tue Apr 07, 2015 8:28 pm
by Joe7349603

So I noticed a weird behaviour with array that I hope someone can help me understand what is happening- not sure this is a bug in Appery.I have a collection that I have columns that I want to use to autocomplete input boxes. What I have realized is that, for example in column KEYWORD i have 30 rows all full with data but for next row which is ROUTES I only have about 20 rows populated because that's all I need.

When I push my array I get Null values for the 10 rows which have no data (which is expected) but then in that a case the autocomplete doesn't work and it throws an error
"cannot read property value of undefined". Is there a trick that can help me overcome this issue without having to create a new collection for each autocomplete I need to have in my app, the other option is to use dummy data to fill the 10 empty rows but that is not feasible because that confuses the user. any idea?

Here is the code I am using
code// Service Success Event
arr = new Array();
$(data).each(function(){ arr.push($(this)[0].keyword); });
localStorage.setItem("Traffic_offence_keyword", JSON.stringify(arr)); // This is just to save the return values to persistent storage for retrieval later.

Routearr = new Array();
$(data).each(function(){ Routearr.push($(this)[0].routes); });
localStorage.setItem("route_keyword", JSON.stringify(Routearr)); /code

Image Image


Stringify JSON parsing data and finding data saved in JSON

Posted: Tue Apr 07, 2015 8:59 pm
by M&M

All you need to do is this

arr = new Array();

$(data).each(function(){

If ($(this)[0].keyword) { // Not Null Check

Code: Select all

      arr.push($(this)[0].keyword); 

}

});

You can do the same for other loop also

Subsequently you can even do a arr.length > 0 to check if the array has been populated with at least 1 value and if not then you can clear / disable the autocomplete cos anyway it doesn't have any values


Stringify JSON parsing data and finding data saved in JSON

Posted: Thu Apr 09, 2015 12:50 am
by Joe7349603

Something is a miss here I cannot get rid of the error: If is not defined.

I am working with new array (Routearr) , and new field (routes). To try and fix the error I added a check to see if array is empty (!=null) I also added a ; after the if statement but nothing.. is there anything missing from you original code?

codeRoutearr = new Array();

$(data).each(function(){

If ($(this)[0].routes !=null); { // Not Null Check

Routearr.push($(this)[0].routes);

localStorage.setItem("route_keyword", JSON.stringify(Routearr));

Appery("RouteNumber_textinput").autocomplete({source: Routearr});
}

}); /code


Stringify JSON parsing data and finding data saved in JSON

Posted: Thu Apr 09, 2015 6:11 am
by M&M

You can try something like this

code
var Routearr = new Array();
var route = null;

$(data).each(function(){
route = $(this)[0].routes;
If (route) { // Not Null Check
route = route.trim();
if (route.length > 0) { // An added check for length
Routearr.push(route);
}
}
});

// The below 2 lines were inside the loop before. They should be outside
localStorage.setItem("route_keyword", JSON.stringify(Routearr));
Appery("RouteNumber_textinput").autocomplete({source: Routearr});
/code

For debugging what you can do is to comment out the last 2 lines. Then put a console.log in the loop and try printing the values to the console. Once confirmed that the array is being populated correctly without errors, then enable the 2nd last line. That'll confirm that the Local Storage variable is being set correctly and that there are no errors when doing then. Then finally enable the last line to assign the autocomplete values to the input control


Stringify JSON parsing data and finding data saved in JSON

Posted: Sun Apr 12, 2015 5:54 am
by Joe7349603

The code above still didn't work but I found a work around that you can use. It is a Jquery function that cleans all null values. Thanks for your help there man appreciated it! Here is the final code that works the way I wanted it..

code var Routearr = new Array();

$(data).each(function(){ Routearr.push($(this)[0].routes); });

//remove all the null values from the array otherwise the Autocomplete wont work.

Routearr = $.grep(Routearr,function(n){ return(n);});.

localStorage.setItem("route_keyword", JSON.stringify(Routearr));

Appery("RouteNumber_textinput").autocomplete({source: Routearr}); /code


Stringify JSON parsing data and finding data saved in JSON

Posted: Thu Apr 23, 2015 6:35 pm
by Joe7349603

M&M,

Considering you have the same code as I do for the autocmplete, did you find it breaking the Slider? In my page, the JS code doesn't jell with Appery which means breaks the slider handles, I am not sure if you have a slider in any of your APP or you encountered this issue.

You can see the full issue here: https://getsatisfaction.com/apperyio/...


Stringify JSON parsing data and finding data saved in JSON

Posted: Fri Apr 24, 2015 3:50 am
by M&M

Well, there is one trick that you can try. I am not too sure how well it works, or whether it will break something else but what I did was to copy/paste the jquery-ui.js code into a local JS file and commented out the lines from 12653 to 13305. I have attached an image for reference.

You can also create the JS file by choosing "Create from URL" when creating the JS resource and point to http://code.jquery.com/ui/1.10.3/jque... Image

Haven't had the time to test it but it may help fix this problem


Stringify JSON parsing data and finding data saved in JSON

Posted: Mon Feb 06, 2017 1:44 pm
by Deon

Hi I have similar issue but I am unable to parse the LSV. I just get object object returned after parsing the LSV

This is my LSV

{
"resource": [
{
"userID":1,
"classID":1
},
{
"userID":2,
"classID":2
}
]
}

var sendID = Apperyio.storage.userIDList.get();
alert(sendID); //Above LSV retuened
sendID = JSON.parse(sendID);
alert(sendID); // object object retuened here
var lsvResult = sendID.resource;
console.log("In below should be array:");
console.log(lsvResult);
for(var i = 0; i < lsvResult.length; i++){
var currentStatusResult = lsvResult;
console.log("lsvResult[" + i + "] = " + currentStatusResult.ApplicationDate);
}
alert(lsvResult);


Stringify JSON parsing data and finding data saved in JSON

Posted: Wed Feb 08, 2017 7:27 pm
by Serhii Kulibaba

Hello Deon,

Please use JSON.parse only to parse strings with JSON. If your Storage variable has a type which differs from string (e.g based on the Model) -don't use it, just read it's value prevar sendID = Apperyio&#46;storage&#46;userIDList&#46;get(); /pre