【发布时间】:2011-08-17 07:43:57
【问题描述】:
嗨,我的 setDefaultPoint 控制器以 json 格式返回地图...代码如下
def setDefaultPoint = {
if (springSecurityService.isLoggedIn()) {
def officeId = params.officeId
def officeRoleInstance=OfficeRole.get(officeId)
def company= officeRoleInstance.company
def defaultPoint = officeRoleInstance.distanceChart.officePoint
def map = [defaultPoint:defaultPoint]
map << [company:company]
def json = map as JSON
render json
}
向这个控制器发送请求的ajax调用是
function setDefaultPoint(){
var officeId = $('#clientTrip_officeId').val();
$.ajax({
url:"${createLink(controller:'clientTrip',action:'setDefaultPoint')}",
dataType: "json",
data:({officeId: officeId}),
success: function(data) {
// here i want to get the id and name of default point and id and name of company...
console.log('id of defaultpoint is---"+????)
console.log('name of default point is---"+????)
console.log(id of company is-----------"+?????)
}
});
}
我从 json 传递了两个不同的对象.. 那么如何获取这些对象的属性... defaultPoint 对象和 Company 对象都有名为 id 和 anme 的字段
响应看起来像
{"defaultPoint":{"class":"com.springpeople.steer.trips.Point","id":3,"name":"MG road"},"company":{"class":"com.springpeople.steer.partymodel.parties.Company","id":5,"addressPermanent":{"class":"Address","id":3},"contactDetails":null,"name":"Infosys","offices":[{"class":"OfficeRole","id":6}],"organizationRoles":[{"class":"OrganizationRole","id":5}],"panNumber":null,"serviceTaxNumber":null,"tanNumber":null}}
【问题讨论】: