我想在使用json的extjs中創建一個gridview。出於某種原因,我的gridview沒有顯示任何數據。我試圖用螢火蟲進行調試。我可以在「回覆」部分看到結果。 這就是我在「Reponse」中所擁有的。Extjs Gridview顯示無數據
{ 「ContentEncoding」:空 「的ContentType」:空 「數據」: 「{\ r \ n \」 myTable的\ 「:[\ r \ N {\ r \ n \」 Q1 \」 :\「1 \」,\ r \ n \「Q2 \」:\「1 \」,\ r \ n \「Q3 \」:\「 「1 \」,\ r \ n \「改進\」:\「\」,\ r \ n \「註釋\」:\「1 \」\ r \ n},\ r \ n {\ r \ n \「Q1 \」:\「1 \」,\ r \ n \「Q2 \」:\「2 \」,\ r \ n \「Q3 \」:\「3 \」,\ r \ n \「 Q4 \「:\」4 \「,\ r \ n \」改進\「:\」Iphone5 \「,\ r \ n \」註釋\「:\」Iphone14 \「\ r \ n} \ r \ \ n \ n \ n \ n \「\ n \」\「\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Q3 \ \ r \ n \「Q4 \」:\「3 \」,\ r \ n \「改進\」:\「This Comment1-3 \」,\ r \ n \「Comments \」:\「 Comment2-3 \ 「\ r \ N} \ r \ n]的\ r \ N}」, 「JsonRequestBehavior」:0}
更新 其實我用JSON現在看到這一點,但我的GridView控件仍然是空的 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);
}
});
和/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);
}
}
}
任何一種的投入會有很大的幫助...謝謝
謝謝您的回答Johan ...我試圖做到這一點,現在我只是得到一個空白頁...也就回應,我只看到我的代碼...我得到循環引用錯誤,當我只使用返回Json(new {data = myData1},JsonRequestBehavior.AllowGet); – EagleFox
我知道了約翰......事實證明我已經注意到了我的商店......解決了這個問題並嘗試了你的解決方案......砰的一聲就像魅力一樣......非常感謝你......現在我要嘗試使用模型... – EagleFox