Milton Davis
Posts: 0
Joined: Tue Mar 04, 2014 5:12 am

Limit entires to a Grid

I am using a REST service to get data from Google Places. It returns 20 entries in a JSON file. Is there anyone to map the response to a Grid object, so that only the first 3 entries show up? I have it working so all 20 show, but want to limit the number of results.

Image

Milton Davis
Posts: 0
Joined: Tue Mar 04, 2014 5:12 am

Limit entires to a Grid

My JSON file is coming fron Google api so there is no linit parameter. It returns a file with 20 records every time. Is there a way to limit these to only the first 5 entries displaying in a grid?

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Limit entires to a Grid

You should change service incoming answer.

For this goals you should use service wrapper "Generic Security context".

Algorithm is:

1 service receive the response.

2 Generic security context get this response and change it(in your case you should to delete unnecessary items)

3 Return modified object.

Please read this document about it: http://docs.appery.io/documentation/g...

Milton Davis
Posts: 0
Joined: Tue Mar 04, 2014 5:12 am

Limit entires to a Grid

Igor,

I think I need to use Generic Security Context, but I am not understanding how to set it up from the document you provided. Can you help me with the JavaScript?

From the document, I don't understand what calls my GooglePlaces service or my GenericSecurityContext service.

My Service is called GooglePlaces, and it returns a JSON like this:
{

Code: Select all

"html_attributions" : [ 

 ], 

"results" : [ 

   { 

      "geometry" : { 

         "location" : { 

            "lat" : 33.885201, 

            "lng" : -118.410797 

             } 

         }, 

   { 

      "geometry" : { 

         "location" : { 

            "lat" : 33.885158, 

            "lng" : -118.410012 

}

}

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Limit entires to a Grid

Hi Milton,

Please do the following steps:

  1. Create "Generic security context" and call it "MySecurityGeneric".

  2. Open editor for JS implementation for this security context http://prntscr.com/33wngf/direct

  3. Insert following JS code:
    pre
    Appery.MySecurityGeneric = Appery.createClass(SecurityContext, {

    invoke: function(service, settings) {
    var oldSuccess = settings.success;

    Code: Select all

     var onSuccess = function(value, other){ 
    
         console.log("Original object"); 
         console.log(value); 
    
         //here you should to change your object here. For example "value.length = 1;" 
    
         console.log("Changed object"); 
         console.log(value); 
    
         oldSuccess.call(this, value, other); 
     }; 
    
     settings.success = onSuccess; 
     Appery.MySecurityGeneric.$super.invoke.call(this, service, settings); 

}

});
/pre

  1. Navigate to your service. And set this security context (MySecurityGeneric). http://prntscr.com/33wog4/direct

  2. Test it. By Default you should have the same result as before it. But in console log you should get two object (before changes and after).

    So you should implement your object changing logic (object after changes should be the same as object before changes, but with count of items you need).

    That's all.

Milton Davis
Posts: 0
Joined: Tue Mar 04, 2014 5:12 am

Limit entires to a Grid

Illya, thanks for the help, but I still can not get it to work...

I was able to follow what you suggested, but when I test the service, I get no change even after changing the logic. I don't see the JSON in the console either. It doesn't seem like my service is running the security context. Any thoughts?
Image Image Image

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Limit entires to a Grid

Milton.

You have missed this item:
[quote:]

  1. Create "Generic security context" and call it "MySecurityGeneric".
    [/quote]

    See screen shot: http://prntscr.com/33wzvs/direct

    Fix it and try again.

Milton Davis
Posts: 0
Joined: Tue Mar 04, 2014 5:12 am

Limit entires to a Grid

Illya, I made that change and also changed the service to call out "MySecurityGeneric" context now, but it still does not work. It is not running the Security Context code for some reason.

Any idea why?

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Limit entires to a Grid

Hi Milton,

Hard to say what is wrong. Please share your application with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a and tell us its name.

Return to “Issues”