【问题标题】:EXT JS get json data asynchronously and load store using ajax proxyEXT JS 异步获取 json 数据并使用 ajax 代理加载存储
【发布时间】:2014-07-30 01:28:33
【问题描述】:

首先,我是一个 extjs 初学者。我无法使用 ajax 代理加载我的商店。

这是我的模型。

        Ext.define('alertTemplates', {
        extend: 'Ext.data.Model',
        fields: ['text','config', {name: 'label', convert: function(v,record) {
            if (Ext.isEmpty(record.data.text))
                return nodeTemplate.apply(record.data.config);
            else return record.data.text;
        }}]
    });

正在尝试加载商店

        var store = Ext.create('Ext.data.TreeStore', {
        model: 'alertTemplates',
        proxy:{
            type: 'ajax',
            url: '/alfresco/service/alertTemplates.json?alf_ticket=' + user.authTicket,
            reader:{
                root:'children',
                type: 'json'
            },
            autoLoad: true,
            excludeContext: true,
            method: 'GET',
            params: {
                nodeRef: currentProject.nodeRef
            },
            scope: this,
            listeners: {
                load: function(){
                    console.log('loaded');
                }
            }
        }
    });

    store.load();

我知道我正在正确检索数据。我之前使用过下面的代码,响应中包含我想要获取的 json 代码。我是否以正确的方式处理这个问题?

        Jx.Utils.ajax({
        url: '/alfresco/service/alertTemplates.json?alf_ticket=' + user.authTicket,
        excludeContext: true,
        method: 'GET',
        params: {
            nodeRef: currentProject.nodeRef
        },
        scope: this,
        success: function (response)
        {
            var alertTemplates = response.json;
            console.log(alertTemplates);

            store.loadRawData(alertTemplates,true);

        },
        failure:  console.log('failed')
    });

【问题讨论】:

    标签: ajax json extjs asynchronous get


    【解决方案1】:

    我在店里注意到的几件事:

    • autoLoad 需要在商店级别,而不是在代理内部:。
    • 侦听器需要在代理之外:。
    • 方法:需要在代理内部:。

    另外,我不确定 excludeContext 是什么。您使用的是哪个版本的 EXTJS?

    这里有一个小重组给你一个想法。如果 autoLoad 为 true,则无需手动加载。

    var store = Ext.create('Ext.data.TreeStore', {
        model: 'alertTemplates',
        autoLoad: true,
        proxy:{
            type: 'ajax',
            url: '/alfresco/service/alertTemplates.json?alf_ticket=' + user.authTicket,
            method: 'GET',
            reader:{
                root:'children',
                type: 'json'
            },
            //excludeContext: true,
            params: {
            nodeRef: currentProject.nodeRef
            }
        },
        scope: this,
        listeners: {
            load: function(){
                console.log('loaded');
            }
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2012-02-11
      • 2013-09-14
      • 2011-11-18
      • 2013-07-28
      • 2012-07-12
      • 1970-01-01
      • 1970-01-01
      • 2012-12-04
      • 1970-01-01
      相关资源
      最近更新 更多