【问题标题】:ExtJS 4.2 - Error Loading Store From Command - Data Returned From Service - MVC SetupExtJS 4.2 - 从命令加载存储时出错 - 从服务返回的数据 - MVC 设置
【发布时间】:2013-07-15 20:37:53
【问题描述】:

我在学习 ExtJS 时遇到了各种各样的问题(我是一名 flex 开发人员)。目前,我不确定如何从命令加载商店。我有一个命令,我可以在其中进行服务调用并获取数据。然后我想用这些数据加载模型(从命令内部)。

我的代码...

PhoneCallsLoadCommand.js:(命令)

Ext.define('DG.controller.PhoneCallsLoadCommand', {
    extend: 'Ext.app.Controller',
    stores: ['PhoneCalls'],
    models: ['PhoneCall'],

    views: [
        'PhoneCallListView'
    ],

    init: function () {
        var url2 = "https://MyServiceURLWSDL";
        var pl = new SOAPClientParameters();
        pl.add("arg0", false);

        SOAPClient.invoke(url2, "gePaymentsMethod", pl, true, getDataCallback);

        function getDataCallback(response) {
        // This is where I want to load the response data into the Model
            var store = Ext.getStore('phoneCallsStore');
            store.loadData(response);
        }
    }
});

这是从服务调用返回的响应 XML 数据:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <dlwmin:getPaymentsMethod xmlns:dlwmin="http://blahblah.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <return>
            <contents>
               <eftAcctNo>501014635986</eftAcctNo>
               <empSsn>122400724</eftAcctRoutNo>
            </contents>
            <contents>
               <eftAcctNo></eftAcctNo>
               <empSsn></eftAcctRoutNo>
            </contents>
            <contents>
               <eftAcctNo></eftAcctNo>
               <empSsn></eftAcctRoutNo>
            </contents>
            <status>0</status>
         </return>
      </dlwmin:getPaymentsMethod>
   </soapenv:Body>
</soapenv:Envelope>

我需要将此响应数据填充到我的模型中,以便在我的网格中使用它。

PhoneCall.js:(型号)

Ext.define('DG.model.PhoneCall', {
    extend: 'Ext.data.Model',
    config: {
        idProperty: 'phoneCallModel',
        fields: [
            {name: "eftAcctNo", type: "string"},
            {name: "empSsn", type: "string"}
        ]
    }
});

PhoneCalls.js(存储)

Ext.define('DG.store.PhoneCalls', {
    extend: 'Ext.data.Store',
    config: {
        storeId: 'phoneCallsStore',
        model: 'DG.model.PhoneCall',
        autoLoad: false
    },
    proxy: {
        type: 'memory',
        reader: {
            type: 'xml',
            record: 'contents',
            //rootProperty: 'return'
        }
    },
    listeners: {
        'load' : function() {
            console.log("Making Service Call...");
        }
    }
});

在命令中,当我这样做时:

var store = Ext.getStore('phoneCallsStore');
            store.loadData(response);

我收到以下错误: 未捕获的类型错误:无法调用未定义的方法“loadData”

谁能告诉我如何将响应数据加载到模型中?我的视图是一个指向模型的网格。

PhoneCallListView.js (查看)

Ext.define('DG.view.PhoneCallListView' ,{
    extend: 'Ext.grid.Panel',
    alias: 'widget.phoneCallListView',
    title: 'Phone Calls DataGrid',

    // we no longer define the Phone Calls store in the 'initComponent' method
    store: 'PhoneCalls',

    initComponent: function() {
        this.columns = [
            {header: 'Eft Acct No', dataIndex: 'eftAcctNo', flex:1},
            {header: 'Emp Ssn', dataIndex: 'empSsn', flex:1},
        ];

        this.callParent(arguments);
    }
});

仅供参考 - 我无法让 Store 使用 ajax 代理进行服务调用,所以我发现使用 soapclient.js 很容易。 谢谢

【问题讨论】:

    标签: extjs extjs4 extjs-mvc


    【解决方案1】:

    行:Uncaught TypeError: Cannot call method 'loadData' of undefined 告诉我您的商店未定义。由于您的商店名为DG.store.PhoneCalls,因此您应该使用Ext.getStore('PhoneCalls'),并确保您在控制器中使用了stores: ['PhoneCalls'] 配置。

    虽然您可能在使用 Ajax 代理时遇到了麻烦,但您确实应该尝试找到一种方法来使其正常工作。您尝试在此处加载商店的方式非常简单。也许你应该使用XmlStorehttp://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.XmlStore

    【讨论】:

    • 如果你看我上面的代码,我在命令中有存储:['PhoneCalls']。另外,我尝试过 Ext.getStore('PhoneCalls') 并且还使用了商店的 id。都不行。
    • 如我所说,Uncaught TypeError: Cannot call method 'loadData' of undefined 表示您的商店未正确检索。尝试将您的 stores: ['PhoneCalls'] 行移动到您的 app.js gile。
    【解决方案2】:

    这就是最终对我有用的东西:

        function getDataCallback(req, r) {
            var store = Ext.getStore('PhoneCalls');
            store.loadRawData(r);
            store.sync();
        }
    

    【讨论】:

      猜你喜欢
      • 2016-09-29
      • 1970-01-01
      • 2013-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-28
      • 2012-02-14
      • 1970-01-01
      相关资源
      最近更新 更多