Page 2 of 3

How do I add search results to another page?

Posted: Thu Mar 06, 2014 1:55 am
by Alex6694044

I have tried implementing the JS, but it is not working and I keep getting:

"stored show is = iframe_viewport" in the console.

Any reason why this would be happening?


How do I add search results to another page?

Posted: Thu Mar 06, 2014 2:51 am
by Igor

Alex,

Could you show us what you tried and what doesn't work. It would help us if you show
us some screenshots or public link with steps how to reproduce this or JS code.


How do I add search results to another page?

Posted: Thu Mar 06, 2014 4:58 am
by Alex6694044

Sure, here is the link to the public app: http://appery.io/app/mobile-frame?src...

As you can see, what I am try to do is search for a show, and add the show to a list on the other page.

Here is the search page:
Image
with the following mapping:
Image
and added the JS here:
Image
Then, on the main page, I added the JS:
Image
with the following mapping:
Image

Currently, I am getting a console response of "stored show is = ". So it looks like nothing is getting stored in the JS, but I do not know how to fix it.


How do I add search results to another page?

Posted: Thu Mar 06, 2014 5:06 am
by Alex6694044

Also, the public version of the app might not work for you (I have to disable my Chrome web security or else I get an Origin-Not-Allowed error).


How do I add search results to another page?

Posted: Thu Mar 06, 2014 9:27 am
by Nikita

Hi Alex,

You should use a proxy for the service: http://docs.appery.io/documentation/s...


How do I add search results to another page?

Posted: Thu Mar 06, 2014 7:24 pm
by Alex6694044

Thank you! That cleared up the error!


How do I add search results to another page?

Posted: Thu Mar 06, 2014 10:53 pm
by Alex6694044

Okay, so now I am able to store these seriesID's into my LSV (thank you Igor). I did this adding the following JS to the search page after a list item is clicked and a LSV is set with the seriesID:

//here is id of element that's user clicked on.
var id = [];
id = JSON.parse(localStorage.getItem('seriesID'));
var storedShows = localStorage.getItem("storedShows");
if(!storedShows)
storedShows = "{}";
storedShows = JSON.parse(storedShows);
storedShows[id] = {};
localStorage.setItem("storedShows", JSON.stringify(storedShows));
console.log(id);

Now, all I need to do is pass those seriesIDs into the DB service on the My Shows page to retrieve the show information. At the moment, it is still only listing the latest one added. I can see in the console that all of them are actually stored there. I have tried adding the following code to the "where", on service success, and on page load with no success:

var storedShows = localStorage.getItem("storedShows");
storedShows = JSON.parse(storedShows);
//Add code which restore selected show in the previous page
var id;
try {
id = JSON.parse(localStorage.getItem("id"));
if ({}.toString.call(id) !== "[object Array]") {
id = [];
}
} catch ( e ) {
id = [];
}
for (var i in storedShows)
console.log("stored show is = " + i);

Does this look right? And if so, where should I put it?


How do I add search results to another page?

Posted: Fri Mar 07, 2014 3:17 am
by Illya Stepanov

Hi Alex,

Please provide us more details of your application and what problems you have implementing it. Some screenshots from app, mappings and describing how it should work and what doesn't work, would definitely help.

Thanks.

So if you have saved your choosed items to lsv you have to do next:
ol
li - on the second page create "query" service (you have done it already)./li
li - in the "where" parameter to this service add JS. And implement js which returns "_id" filtering with "$in" clause: (it's better to do it yourself)/li
/ol
Please read about "$in" clause here: http://docs.appery.io/documentation/b... (you can navigate directly to "Contained in ($in)" - but it's recomended to read this topic completely).


How do I add search results to another page?

Posted: Wed Mar 12, 2014 3:15 am
by Alex6694044

So my application is really pretty simple. It is meant to allow users to track the episodes of TV series they like. There are currently two pages: mainPage and searchPage. On searchPage, a user searches for and adds the TV series to their mainPage. On mainPage, it displays a listing of all of the TV series they want to track.

Search Page:

  1. User inputs series name
    Image

  2. API retrieves all series matching input
    Image

  3. User clicks on series name, then:
    (a) seriesID is added to LSV
    (b) the following JS is run:
    precode//here is id of element that's user clicked on.
    var id = [];
    id = JSON.parse(localStorage.getItem('seriesID'));
    var storedShows = localStorage.getItem("storedShows");
    if(!storedShows)
    storedShows = "{}&quot
    storedShows = JSON.parse(storedShows);
    storedShows[id] = {};
    localStorage.setItem("storedShows", JSON.stringify(storedShows));
    console.log(id);/code/pre
    (c) navigates user to the Main Page

    Main Page:

  4. API is invoked on load

  5. API requests seriesID stored in LSV
    (a) 'where' used to retrieve all seriesID's in LSV by the following JS:
    precodevar storedShows = localStorage.getItem("storedShows");
    storedShows = JSON.parse(storedShows);
    //Add code which restore selected show in the previous page
    for (var i in storedShows)
    console.log("stored show is = " + i);/code/pre
    Image

  6. API responds with seriesID and seriesName and inserts them into labels on mobile list items
    Image

  7. Main Page displays a listing of all series stored as a LSV

    Eventually, once I get the users list of series to show, I would like to gather all episodes and put them into a calendar/list and use this to send notifications to the user of the upcoming episode airing.

    Here is my problem:

    The Main Page is not displaying a listing of the added series, it is only displaying the most recent one added. I can tell the added series are in local storage because they are showing up with in the console with console.log("stored show is = " + i).

    So, what do I need to do to get my Main Page to display the users TV series?

    I read about the $in clause, however, it gives no direction on using this with local storage. It seems what I need to do is make changes to the 'where' request on the mainPage, but I am not sure what else I would need to include in the JavaScript I already have. It seems like it should work already.

    (public version of app: http://appery.io/app/mobile-frame?src...)

    Thank you for your help.


How do I add search results to another page?

Posted: Wed Mar 12, 2014 4:55 am
by Igor

Please replace your code:

pre
code
(a) 'where' used to retrieve all seriesID's in LSV by the following JS:

var storedShows = localStorage.getItem("storedShows");
storedShows = JSON.parse(storedShows);
//Add code which restore selected show in the previous page
for (var i in storedShows)
console.log("stored show is = " + i);
/code
/pre

with the following:
pre
code
var storedShows = localStorage.getItem("storedShows");
storedShows = JSON.parse(storedShows);

var whereObject = {"_id": {"$in": [] } };

//Add code which restore selected show in the previous page
for (var i in storedShows){
whereObject._id.$in.push(i);
console.log("stored show is = " + i);
};

return JSON.stringify(whereObject);
/code
/pre