Extjs Gridview显示无数据 [英] Extjs Gridview Shows No Data

查看:195
本文介绍了Extjs Gridview显示无数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用json在extjs中创建一个gridview。由于某种原因,我的gridview不显示任何数据。我试图用firebug来调试它。我可以在响应部分看到结果。
这是我在回复中的。


{ContentEncoding:null,ContentType:null,数据:{\r\\\
\myTable\:[\r\\\
{\r\\\
\Q1 \:\1 \,\\ \\\\\\Q2\:\1 \,\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\Q4 \:\1 \,\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \1\\r\\\
},\r\\\
{\r\\\
\Q1\:\1\,\\\
\Q2\:\2\,\r\\\
\Q3\:\3\,\\\\\\ :\4\,\\\\\改进\:\Iphone5 \,\\\\\\ \\r\\\
},\r\\\
{\r\\\
\Q1 \ 1\,\\\\\\Q2\:\1 \,\\\\\\\ \r\\\
\Q4\:\3\,\r\\\
\改进\:\这是Comment1-3\,\ r\\\
\Comments\:\这是Comment2-3\\r\\\
} \r\\\
] \r\\\
},JsonRequestBehavior: 0}


更新
其实我在Json看到现在,但我的gridview仍然是空的
请点击这里查看我的JSON



/GridViewApp.js

  Ext.define('GridViewApp.view。 GridViewApp',{
alias:'widget.gridviewapp',
width:800,
title:'我的网格面板',
grid:null,
store: null,
layout:{
type:'anchor'
},
构造函数:function(){

this.callParent(argume NTS);

var store = Ext.create('Ext.data.Store',{

storeId:'myData',
scope:this,
字段:[
{name:'Q1',type:'int'},
{name:'Q2',type:'int'},
{name:'Q3'类型:'int'},
{name:'Q4',type:'int'},
{name:'Q5',type:'int'},
{name: '改进',键入:'string'},
{name:'注释',键入:'string'}
],

分类器:[
{
// property:'myData',
direct:'ASC'
}
],

proxy:{
type:' ajax',
范围:this,
url:'GridView / writeRecord',
reader:{
type:'json',
root:'myTable'
idProperty:'ID '

}
}
});

store.load();
this.grid = Ext.create('Ext.grid.Panel',{
title:'GridView App',
store:this.store,
columns:[
{header:'Q1',width:100,
sortable:true,dataIndex:'Q1'
},
{header:'Q2',width:100,
sortable:true,dataIndex:'Q2'
},
{header:'Q3',width:100,
sortable:true,dataIndex:'Q3'
} ,
{header:'Q4',width:100,
sortable:true,dataIndex:'Q4'
},
{header:'Improvements',width:
sortable:true,dataIndex:'Improvements'
},
{header:'Comments',width:200,
sortable:true,dataIndex:'Comments'
}
],
stripeRows:true,
width:800,
renderTo:Ext.getBody()
});
this.add(this.grid);
}
});

和/GridViewController.cs

 命名空间GridViewApp.Controllers 
{
public class GridViewController:Controller
{

public ActionResult Index()
{
return View();
}


public JsonResult writeRecord()
{

SqlConnection conn = DBTools.GetDBConnection(ApplicationServices2);


string sqlquery =SELECT Q1,Q2,Q3,Q4,改进,来自myTable的注释;
SqlDataAdapter cmd = new SqlDataAdapter(sqlquery,conn);

DataSet myData = new DataSet();
cmd.Fill(myData,myTable);

conn.Open();

conn.Close();


string myData1 = JsonConvert.SerializeObject(myData,Formatting.Indented,
new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
} );

return Json(new {data = myData1},JsonRequestBehavior.AllowGet);
}

}
}

任何种类的输入将是一个很大的帮助...谢谢

解决方案

这是一个很古老的逻辑,它返回一个字符串。



您将json.net序列化为字符串。然后你用Json()序列化该字符串。你应该只使用json.net序列化。

  public string writeRecord()
{

SqlConnection conn = DBTools.GetDBConnection(ApplicationServices2);


string sqlquery =SELECT Q1,Q2,Q3,Q4,改进,来自myTable的注释;
SqlDataAdapter cmd = new SqlDataAdapter(sqlquery,conn);

DataSet myData = new DataSet();
cmd.Fill(myData,myTable);

conn.Open();

conn.Close();


返回myData1 = JsonConvert.SerializeObject(myData,Formatting.Indented,
new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
} );

}


I am trying to create a gridview in extjs using json. For some reason my gridview does not show any data. I tried to debug it with firebug. I can see the results in "Response" section. This is what I have in "Reponse".

{"ContentEncoding":null,"ContentType":null,"Data":"{\r\n \"myTable\": [\r\n {\r\n \"Q1\": \"1\",\r\n \"Q2\": \"1\",\r\n \"Q3\": \"1\",\r\n \"Q4\": \"1\",\r\n \"Improvements\": \"\",\r\n \"Comments\": \"1\"\r\n },\r\n {\r\n \"Q1\": \"1\",\r\n \"Q2\": \"2\",\r\n \"Q3\": \"3\",\r\n \"Q4\": \"4\",\r\n \"Improvements\": \"Iphone5\",\r\n \"Comments\": \"Iphone14\"\r\n },\r\n {\r\n \"Q1\": \"1\",\r\n \"Q2\": \"1\",\r\n \"Q3\": \"3\",\r\n \"Q4\": \"3\",\r\n \"Improvements\": \"This is Comment1-3\",\r\n \"Comments\": \"This is Comment2-3\"\r\n }\r\n ]\r\n}","JsonRequestBehavior":0}

Update Actually I see this in Json now, but my gridview is still empty Please click here to see my JSON

/GridViewApp.js

Ext.define('GridViewApp.view.GridViewApp', {
alias: 'widget.gridviewapp',
width: 800,
title: 'My Grid Panel',
grid: null,
store: null,
layout: {
    type: 'anchor'
},
constructor: function () {

    this.callParent(arguments);

    var store = Ext.create('Ext.data.Store', {

        storeId: 'myData',
        scope: this,
        fields: [
        { name: 'Q1', type: 'int' },
        { name: 'Q2', type: 'int' },
        { name: 'Q3', type: 'int' },
        { name: 'Q4', type: 'int' },
        { name: 'Q5', type: 'int' },
        { name: 'Improvements', type: 'string' },
        { name: 'Comments', type: 'string' }
        ],

        sorters: [
            {
                //property: 'myData',
                direct: 'ASC'
            }
         ],

        proxy: {
            type: 'ajax',
            scope: this,
            url: 'GridView/writeRecord',
            reader: {
                type: 'json',
                root: 'myTable',
                idProperty: 'ID'

                }
        } 
    });

    store.load();   
    this.grid = Ext.create('Ext.grid.Panel', {
        title: 'GridView App',
        store: this.store,
        columns: [
            {header: 'Q1', width: 100,
        sortable: true, dataIndex: 'Q1'
                    },
        { header: 'Q2', width: 100,
            sortable: true, dataIndex: 'Q2'
        },
        { header: 'Q3', width: 100,
            sortable: true, dataIndex: 'Q3'
        },
                    { header: 'Q4', width: 100,
                        sortable: true, dataIndex: 'Q4'
                    },
                    { header: 'Improvements', width: 200,
                        sortable: true, dataIndex: 'Improvements'
                    },
                    { header: 'Comments', width: 200,
                        sortable: true, dataIndex: 'Comments'
                    }
    ],
        stripeRows: true,
        width: 800,
        renderTo: Ext.getBody()
    });
    this.add(this.grid);
}
});

and /GridViewController.cs

namespace GridViewApp.Controllers
{
public class GridViewController : Controller
{

    public ActionResult Index()
    {
        return View();
    }


    public JsonResult writeRecord()
    {

        SqlConnection conn = DBTools.GetDBConnection("ApplicationServices2");


        string sqlquery = "SELECT Q1, Q2, Q3, Q4, Improvements, Comments FROM myTable";
        SqlDataAdapter cmd = new SqlDataAdapter(sqlquery, conn);

        DataSet myData = new DataSet();
        cmd.Fill(myData, "myTable");

        conn.Open();

        conn.Close();


        string myData1 = JsonConvert.SerializeObject(myData, Formatting.Indented,
                        new JsonSerializerSettings
                        {
                            ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                        });

        return Json(new { data = myData1 }, JsonRequestBehavior.AllowGet);
    } 

}
}

Any kind of input will be a big help... Thank you

解决方案

It's pretty logic that it returns a string.

You serialize with json.net into a string. Then you serialize that string with Json(). You should only use the json.net serialization.

public string writeRecord()
{

    SqlConnection conn = DBTools.GetDBConnection("ApplicationServices2");


    string sqlquery = "SELECT Q1, Q2, Q3, Q4, Improvements, Comments FROM myTable";
    SqlDataAdapter cmd = new SqlDataAdapter(sqlquery, conn);

    DataSet myData = new DataSet();
    cmd.Fill(myData, "myTable");

    conn.Open();

    conn.Close();


    return myData1 = JsonConvert.SerializeObject(myData, Formatting.Indented,
                    new JsonSerializerSettings
                    {
                        ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                    });

} 

这篇关于Extjs Gridview显示无数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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