Kendo UI网格没有填充数据

时间:2013-07-22 21:01:53

标签: json kendo-ui kendo-grid

我正在尝试使用Kendo UI Grid来填充数据库中的数据。我正在创建的应用程序是使用Spring 3.2,Hibernate4和Jackson Fasterxml。我知道我的控制器正在返回JSON。我知道这一点,因为当我点击为控制器调用的URL时,我得到以下JSON响应:

[{"applicationId":11,"applicationName":"LOS","url":"test.com","serverId":1,"serverName":"vmlosweb01","serverIp":"10.49.10.89","createdDate":1373644385213,"modifiedDate":null,"genericUserName":"lsdefault","genericPassword":"password1","orgId":null,"environmentId":1,"environmentName":"SANDBOX","createdDate":1373904291147,"modifiedDate":null,"databaseInfoId":1,"databaseName":"SANDBOX Database","ipAddress":"10.49.10.145","environmentId":1,"environmentName":"SANDBOX","createdDate":1373904291147,"modifiedDate":null,"createdDate":1373904415710,"modifiedDate":null,"createdDate":1374169441500,"modifiedDate":null}]

这是我的代码:

appinfo.js

$(document).ready(function () {


var dataSource = new kendo.data.DataSource({
    transport: {
        read: {
            read: "/appinfo/findApplications",
            dataType: "jsonp"
        }
    },
    pageSize: 10

});

dataSource.fetch(function(){
   var data = this.data();
    console.log(data.length);
});

$("#applicationsGrid").kendoGrid({
    dataSource: dataSource,
    pageable: true,
    height: 600,
    scrollable: true,
    sortable: true,
    filterable: true,
    columns: [
        {field: "applicationName", title: "Application Name"},
        {field: "url", title: "URL"},
        {field: "serverId", title: "Server"},
        {field: "environmentId", title: "Environment"},
        {field: "databaseInfoId", title: "Database"},
        {field: "genericUserName", title: "Default Username"},
        {field: "genericPassword", title: "Default Password"}
    ]
});


});

ApplicationInformationController.java

package com.lps.appinfo.controller;


import com.lps.appinfo.model.*;
import com.lps.appinfo.service.ApplicationService;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import com.lps.appinfo.service.DatabaseInfoService;
import com.lps.appinfo.service.EnvironmentService;
import com.lps.appinfo.service.ServerService;


import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@Controller
public class ApplicationInformationController {

private static final Logger logger =    LoggerFactory.getLogger(ApplicationInformationController.class);

@Autowired
private ApplicationService applicationService;
@Autowired
private EnvironmentService environmentService;
@Autowired
private ServerService serverService;
@Autowired
private DatabaseInfoService databaseInfoService;


@RequestMapping(value = "/findApplications", method = RequestMethod.GET, headers = "Accept=application/json")
public
@ResponseBody()
List<Application> findApplications() {
   /* MappingJackson2HttpMessageConverter json = new MappingJackson2HttpMessageConverter();
    MediaType jsonMimeType = MediaType.APPLICATION_JSON;*/


    applicationService = new ApplicationService();
    List<Application> applications = applicationService.getAll();

    // json.write(new Object(), jsonMimeType, new ServletServerHttpResponse());
    return applications;
}




}

当我通过Chrome Debugger调试javascript时,dataSource变量返回的是一个0的数组大小。所以我不确定发生了什么(或者没有发生)。

1 个答案:

答案 0 :(得分:2)

有两个问题:

  1. 您已经定义了结果是JSONP,据我所知,您的响应是JSON。
  2. 数据源定义不正确。在transport定义中,有一个名为read的成员,但url提供为url而不是read
  3. 所以,它应该是:

    var dataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url     : "/appinfo/findApplications",
                dataType: "json"
            }
        },
        pageSize : 10
    });