如何骨干模式绑定到的jqGrid? [英] How to bind Backbone model to jqGrid?

查看:130
本文介绍了如何骨干模式绑定到的jqGrid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用骨干与jQuery和jqGrid的一起并与jqGrid的结合骨干收集遇到的问题。

I'm using Backbone along with jQuery and jqGrid and encountering problem with binding the backbone collection with jqGrid.

这是响应我从服务器获取:

This is the Response I get from Server:

{"DogModel":[
    {"name":"Jane","breed":"Great Dane"},
    {"name":"Rocky","breed":"golden Retriver"},
    {"name":"Jim","breed":"Lab"}
]}

在视图中,我得到这样

[{"name":"Jane","breed":"Great Dane"},
{"name":"Rocky","breed":"golden Retriver"},
{"name":"Jim","breed":"Lab"}]

// jqGgrid code鉴于

//jqGgrid code in view

jQuery("#dogsList").jqGrid({ 
    datatype: 'json',
    data:this.collection.models.toJSON(),
    width:'100%',
    colNames:['name', 'breed'], 
    colModel:[  
        {name:'name', align:'left'},
        {name:'breed', align:'left'}
    ],
    loadComplete : function(data) {
        alert('grid loading completed ' + data);
    },
    loadError : function(xhr, status, error)  {
        alert('grid loading error' + error);
    }
});

我试图替换数据:this.collection.models.toJSON()数据:this.collection.models [0] .toJSON ()数据:this.collection.toJSON(),它会引发意想不到的性格解析错误

I tried replacing data:this.collection.models.toJSON(), with data:this.collection.models[0].toJSON() and data:this.collection.toJSON(), it throws unexpected character parse error.

什么是我需要做的模型结合的jqGrid?

What is that I need to do to bind the model to jqGrid?

推荐答案

我不知道完美的jqGrid,但我看他们的榜样,我找到了一个解决方案,以添加网格模型。

I don't know perfectly jqGrid but I look their examples and I found a solution to add the models on your grid.

您需要将您的数据类型更改为本地并在您的jqGrid手动添加的每一行。

You need to change your datatype to local and add manually each row on your jqGrid.

最好的办法就是看code在工作和的jsfiddle学习code如何工作的:的 http://jsfiddle.net/Atinux/qM98D/

The best thing is to see the code work on jsFiddle and learn how the code works : http://jsfiddle.net/Atinux/qM98D/

这篇关于如何骨干模式绑定到的jqGrid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆