2011-06-11 71 views
1

我有从控制器绑定数据存储的问题。ExtJs 4和asp.net mvc 3数据加载问题。

在JS侧我有以下代码:

function buildGrid() { 
    console.log("0"); 
    var store = new Ext.data.JsonStore(
    { 
     url: '@Url.Content("~/Home/GridData")', 
     root: 'data', 
     totalProperty: 'total', 
     fields: ['Id', 'Name', 'State', 'Age'] 
    }); 
    console.log("1"); 
    store.load({ params: { start: 0, limit: 15} }); 
    console.log("2"); 
} 

控制器代码loks像:

public JsonResult GridData(int start, int limit) 
{ 
    var contact = new List<Contact> { 
     new Contact(){ Name= "Smith", State = "NU", Age =24}, 
     new Contact(){ Name= "Adam", State= "LU", Age =32}, 
     new Contact(){ Name = "Eve", State= "WA", Age=18}, 
     new Contact(){ Name= "Chun Li", State="LI", Age=34} 
    }; 
    return Json(new { total = contact.Count, data = contact, }, JsonRequestBehavior.AllowGet); 
} 

我可以萤火控制台上看到0和1,但代替2-我得到一个错误:

url is undefined 
return url + (url.indexOf('?') === -1 ? '?' : '&') + s; 

ext-all-debug.js (line 5040) 

我不知道我在做什么错。

在此先感谢您的任何建议。

回答

0

我没有解决问题,但我通过创建模型来消除错误。

Ext.define('Contact', { 
    extend: 'Ext.data.Model', 
    fields: ['Id', 'Name', 'State', 'Age'] 
}); 

var store = Ext.create('Ext.data.Store', { 
    model: 'Contact', 
    proxy: { 
     type: 'ajax', 
     url: 'GridData', 
     reader: { 
      type: 'json', 
      record: 'data', 
      totalProperty: 'total' 
     } 
    } 
}); 
-3

也许你应该检查Dextop。它是一个完全致力于促进基于Ext/.NET应用程序开发的应用程序框架。

0

这里的代理,我定义我的店

proxy: { 
    type: 'ajax', 
    batchActions: false, 
    reader: { 
     type: 'json', 
     root: 'data' 
    }, 
    api: { 
     create: 'CreateOrder.json', 
     read: 'ReadOrder.json', 
     update: 'UpdateOrder.json', 
     destroy: 'DestroyOrder.json' 
    }, 
    listeners: { 
     exception: function (proxy, response, operation) { 
      Ext.Msg.show({ 
       title: response.statusText, 
       msg: Ext.decode(response.responseText).message, 
       buttons: Ext.Msg.OK, 
       icon: Ext.window.MessageBox.ERROR 
      }); 
     } 
    } 
} 

你可以尝试一下这个库,这有助于我 extjs4efj