无法通过代理数据调用获取extjs网格

时间:2014-01-14 19:31:33

标签: asp.net-mvc node.js mongodb extjs

我已经从最初的asp.net应用程序中加入了extjs,该应用程序在对任何数据存储进行硬编码并将它们绑定到图表/网格时起作用。当我尝试代理url调用甚至从后面的代码中获取数据并在json中包装时,我仍然没有将数据放入网格中。所以我放弃了,继续使用extjs和nodejs,仍然使用mongodb;这工作得很好,但我仍然需要学习使用express / jade等创建更好的UI,这是一个不同的项目。但后来我遇到了使用带有extjs的MVC,并且一个示例项目尝试了同样的事情(样本有硬编码的数据)而且我不能在我的生活中让它显示数据。

 Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.util.*',
'Ext.state.*'
 ]);

Ext.onReady(function () {
Ext.QuickTips.init();

// setup the state provider, all state information will be saved to a cookie
Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));

Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: [
         { name: 'username', type: 'string' }
  ]
});

Ext.define('UserStore', {
    extend: 'Ext.data.Store',
    model: 'User',
    autoload: true,
    proxy: {
        type: 'ajax',
        url: '/dashboard.aspx/getDBData',
        reader: {
            type: 'json',
            root: 'users'
        },
        listeners:
        {
            exception: function (proxy, response, operation) {
                Ext.MessageBox.show(
                {
                    title: 'REMOTE EXCEPTION',
               msg: operation.getError(), icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK
                });
            }
        }
    }

});

var myStore = Ext.getStore('UserStore');

我在这里包含的url是我最初尝试的代码隐藏函数,它访问mongodb并返回json结果。不工作。 现在从extjs node.js应用程序我得到的结果是localhost:3000 / userlist,它从mongodb返回一个列表并显示如下:

extends layout

block content
h1.
  User List
 u1
 each user, i in userlist
    li
       a(href="mailto:#{user.email}")= user.username

现在可以使用相同的服务器并调用基本URL,然后更改route.js文件以返回mongodb json结果或调用mongodb localhost:27017并获得结果。这里真的很困惑

exports.index = function(db) {
 return function(req, res) {
 var collection = db.get('usercollection');
 collection.find({},{}, function(e,docs){
      res.render('userlist', {
           "userlist" : docs
      });
 });

};  };

编辑:

从asp.net的角度来看,我首先意识到我并没有将web服务称为代码隐藏方法。任何意见仍将受到赞赏。

编辑2:

   {"connTime":null,"userName":"101591196589145","clientName":null,
     "feedUrl":null,"dconnTime":null,"errMessage":null,"ip":null}

1 个答案:

答案 0 :(得分:0)

您已将商店中的根标识为“用户”     读者:{                 输入:'json',                 root:'用户'             },

但是你返回的json中没有root,例如: { “用户”:[{ “connTime”:NULL, “username” 的: “101591196589145”, “CLIENTNAME”:空,      “feedUrl”:NULL, “dconnTime”:NULL, “errMessage”:空, “IP”:空}]}