将 mongodb json 绑定到 kendo 网格

Bind mongodb json to kendo grid

我是 kendo UI 的新手,遇到了如下类似的挑战(除了我不介意网格有固定的数据结构):

How to pass MongoDb Json value to KendoUI grid using webservice method

$("#grid").kendoGrid({

        dataSource: {
        transport: {
            read: {
                url: "http://localhost:8080/urlPath",
                dataType: "json",
               }
            },
    schema: {
            data: "score"
        }
    columns:[{
        field: "physics"
    },
    {
        field: "chemistry",
    }],
   });

Json 看起来像:

[{"score"[{"physics:99", "chemistry" :95}]},{"score"[{"physics:99", "chemistry" :95}]}]

最近几天我一直在苦苦挣扎,并尝试过以下方法:

http://www.codeconfuse.com/2014/03/mongodb-convert-data-getting-from.html

这是上面的相关代码URL:

    while(cursor.hasNext()) { 
        BasicDBObject obj = (BasicDBObject) cursor.next();
        jsonobj = new JSONObject();
        BasicDBList name = (BasicDBList) obj.get("Name");
        jsonobj.put("Incident Date", obj.getString("Incident Date"));
        jsonarray.put(jsonobj);
  }
  return jsonarray;
JSON json =new JSON();
String serialize = json.serialize(cursor);

但是 kendo 网格似乎拒绝了它。请协助。

我的问题已通过格式化返回的 json 以适当的格式解决,如下所示:

发件人:

[{"score"[{"physics:99", "chemistry" :95}]},{"score"[{"physics:99", "chemistry" :95}]**}]**

收件人:

[{"physics:99", "chemistry" :95}]},{"score"[{"physics:99", "chemistry" :95}]

所以,基本上我提取了分数对象,放入我自己的哈希图中,然后返回 json 对象。请参阅下面的示例代码:

*

DB db = mongoClient.getDB( "test" );
DBCollection coll = db.getCollection("mycol");
BasicDBObject fields = new BasicDBObject("score",true).append("_id",false);
BasicDBObject query = new BasicDBObject();

DBCursor cursor = coll.find(query,fields)

while (cursor.hasNext()) {
    DBObject obj = cursor.next();
    BasicDBList scoreList = (BasicDBList) obj.get("score");

for (int i = 0; i < scoreList.size(); i++) {
        BasicDBObject scoreObj = (BasicDBObject) scoreList.get(i);
        String physics = scoreObj.getString("physics");
        String chemistry = scoreObj.getString("chemistry");
        //ofcourse we need another innerloop here to iterate through
        //all the rows of the returned list.   
        innerMap.add("physics",physics);
        innerMap.add("chemistry",chemistry);
    }       
return new Gson().gson(map.values);
}

*