M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

Stringify JSON parsing data and finding data saved in JSON

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

Joe7349603
Posts: 0
Joined: Tue Jan 27, 2015 11:08 pm

Stringify JSON parsing data and finding data saved in JSON

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

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

Stringify JSON parsing data and finding data saved in JSON

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

Joe7349603
Posts: 0
Joined: Tue Jan 27, 2015 11:08 pm

Stringify JSON parsing data and finding data saved in JSON

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

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

Stringify JSON parsing data and finding data saved in JSON

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

Joe7349603
Posts: 0
Joined: Tue Jan 27, 2015 11:08 pm

Stringify JSON parsing data and finding data saved in JSON

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

Joe7349603
Posts: 0
Joined: Tue Jan 27, 2015 11:08 pm

Stringify JSON parsing data and finding data saved in JSON

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/...

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

Stringify JSON parsing data and finding data saved in JSON

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

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Stringify JSON parsing data and finding data saved in JSON

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);

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Stringify JSON parsing data and finding data saved in JSON

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

Return to “Issues”