开发者

Acessing Gorm object in JS

开发者 https://www.devze.com 2023-01-31 02:08 出处:网络
i developed a web application using grails/gorm about traffic reports. Basically, its possible to find for traffic reports like (in road xx there开发者_开发问答 was an accident yyy and the traffic is

i developed a web application using grails/gorm about traffic reports. Basically, its possible to find for traffic reports like (in road xx there开发者_开发问答 was an accident yyy and the traffic is very slow.)

now i need to integrate the map in the application. My map is in javascript, how can i access gorm objects in js (if it is possible)?

standard groovy i use:

<%
       def road1 = packagename.Road.list()

       out << road1.name


%>

Can i have the same kind of access in JS ?


typically for this type of thing you make some sort of request to the server, which returns the data to the browser via JSON or XML. If your map is coming from some javascript library, you can use Ajax to query your server for the data. Which JS library are you using? Whatever it is, it probably has a mechanism to make an ajax request -- you would pass the params on the ajax request that the server needs to get the appropriate data, and when the request returns a callback that define will do something with the data.

As a note, its not a bad idea to set up your application code as follows.

  1. You have your domain object, 'Road'
  2. Generate a RoadService, with a method listAllRoads
  3. Generate a RoadController, with an action listAllRoads

The controller calls the service, the service uses the Domain objects to retrieve the list. In your action, you can take the list and render in whatever form you need (json, xml, or as a gsp).

Grails is all about conventions; the above is how you conform to those conventions.

0

精彩评论

暂无评论...
验证码 换一张
取 消