karavidas Posted January 22, 2015 Share Posted January 22, 2015 hello there!!i m building an app for the elections..in this app i ve build a rest service that takes data(votes,etc) from a .js file of another website,and presents them to some fields.the problem is that.on that js file,the creators provide only "party_id" and not "party_name" which is contained in another .js file.i copied the id's and the names to my database.and now i want that:when the first js file gives the "Party_id",to search the database and provide me the "party_name"..what i want to do is to compare the values given from the rest service and the database collection and to return the correct name. i tried this code: var objectId = value; //Debug information that you can see in browser console.console.log("objectId = " + objectId);var whereObject = {"kwdikos": objectId};return JSON.stringify(whereObject); as shown here,it returns all the database array!! http://imageshack.com/a/img673/9877/EkpHcb.png but as it seems,it returns it without comparing..i mean,i want it when the id sent is 2,to return ND,and when id_sent is 1,to return PASOK.it just displays all the database array without criteria match!i tried to do it by using IF statement,but it didnt let me do it!! the correct results should be these:http://imagizer.imageshack.us/a/img537/7291/d2mTx9.png thanks for your time guys!!! Link to comment Share on other sites More sharing options...
justsomeguy Posted January 22, 2015 Share Posted January 22, 2015 You didn't show enough code to suggest what the problem might be, you need to at least show the actual code that is getting the results.This is just a personal project or something, right? This isn't for an actual election? Link to comment Share on other sites More sharing options...
karavidas Posted January 22, 2015 Author Share Posted January 22, 2015 its my personal project for the actual elections..its not an official one of course!i m trying to make it for me,and if it works correctly to share it with family and friends!i m building it using appery.io platform. i m including screenshots of all states of the app so maybe you could figure out the problem! please please take a look!! i ve made a storage and a model as here: http://imageshack.com/a/img910/3508/WcqssY.jpg and http://imageshack.com/a/img912/6391/RdQ0QZ.jpg then i created 3 services.first,a rest which takes data from the .js file,stores everything on local storage. secondly i created a rest service which takes data from the local storage and queries the database. http://imageshack.com/a/img911/4687/jq0eYa.jpg (before send mapping) the data are displayed like this. http://imageshack.com/a/img905/9840/iiSCct.png and the query is displayed like this:(red color for the right response) http://imagizer.imageshack.us/a/img537/7291/d2mTx9.png as shown here:https://imageshack.com/i/exUJgy7Pjthanks so so much for your time!! i wish you can help me! Link to comment Share on other sites More sharing options...
justsomeguy Posted January 22, 2015 Share Posted January 22, 2015 I'm not familiar with appery.io, I've never used it. Considering that, it's hard for me to guess what the problem might be without seeing some of the other code that it's running. For example, if it's returning incorrect results then I would want to see the code that gets those results to work backwards and figure out the reason. Link to comment Share on other sites More sharing options...
karavidas Posted January 22, 2015 Author Share Posted January 22, 2015 (edited) there is an option to save the whole app as an eclipse project!can i send you this??i think that i have some ideas about where the problem might be! here is the eclipse project.. on ekloges+2014 (5).zipekloges_2014assetswwwa_athinas.jsi think that in line 97 it starts the restful service mapping.. from_name": "restservice1", "from_type": "SERVICE_RESPONSE", "to_name": "A_Athinas", "to_type": "UI", "mappings": [ { "source": "$['body']['party'][i]", "target": "$['mobilegrid_95']" }, { "source": "$['body']['party'][i]['PARTY_ID']", "target": "$['mobilegrid_95']['mobilelabel_126:text']" so i think that problem begins on line 130. Apperyio.mappings["A_Athinas_restservice1_onbeforesend_mapping_0"] = { "homeScreen": "A_Athinas", "directions": [] }; Apperyio.mappings["A_Athinas_restservice2_onsuccess_mapping_0"] = { "homeScreen": "A_Athinas", "directions": [ { "from_name": "restservice2", "from_type": "SERVICE_RESPONSE", "to_name": "A_Athinas", "to_type": "UI", "mappings": [ { "source": "$['body'][i]", "target": "$['mobilegrid_172']" }, { "source": "$['body'][i]['onoma']", "target": "$['mobilegrid_172']['mobilelabel_177:text']" }, { "source": "$['body'][i]['kwdikos']", "target": "$['mobilegrid_172']['mobilelabel_178:text']" } i think that it should create the criteria there..but it doesnt.. if you have some time,take a look..thank you so so so much for the help and your time!!i m really greatefull!! Edited January 22, 2015 by karavidas Link to comment Share on other sites More sharing options...
justsomeguy Posted January 22, 2015 Share Posted January 22, 2015 I don't think I'm going to be able to help with this, you would probably get more help if you found a forum or something for people using the appery platform. Link to comment Share on other sites More sharing options...
karavidas Posted January 22, 2015 Author Share Posted January 22, 2015 (edited) really thanks for your time even if you arent going to be able to help me more!!thanks a lot for trying to help!i have to dig more i think!one last thing!the guys there told me to : create a generic rest service. In this generic service implementation: 2.1. Get first level object. 2.2. Get needed information from first level object. 2.3. Query DB with filter by info from 2.2.(use for this goal query/list service). 2.4. Receive result from 2.3. And put it into result object.(your result object should have all needed information). 2.5. Populate service response settings with correct response parameters. 2.6. Return this object like service response. so if you know any tutorial that will lead me to get the objects and needed info from custom javascript code,please,please let me know!!again,thank you so much!! Edited January 22, 2015 by karavidas Link to comment Share on other sites More sharing options...
justsomeguy Posted January 22, 2015 Share Posted January 22, 2015 I'm good with Javascript in general, but I really have no idea how to work with appery or what kind of environment they provide. Javascript doesn't have a concept of a "service", for example. Link to comment Share on other sites More sharing options...
karavidas Posted January 22, 2015 Author Share Posted January 22, 2015 i see!can i ask you another thing?theoretically,is there any way for me to actually write some js code which will compare 2 js files and return the rows with same id number??is there any tutorial to help me because i m dummy in javascript?? Link to comment Share on other sites More sharing options...
justsomeguy Posted January 23, 2015 Share Posted January 23, 2015 If you have something like 2 arrays of objects, and you want to find the objects that exist in both arrays, that's called an intersection. You should be able to find several algorithms for finding the intersection between 2 arrays, although you'll need to tweak them a little bit if you're looking for an object property (like ID) instead of just comparing the values. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now