【问题标题】:How to set URL in Store's proxy?如何在 Store 的代理中设置 URL?
【发布时间】:2012-06-19 19:22:05
【问题描述】:

我的代码有错误,但我不知道出了什么问题。 当点击 NestedList 的叶项时,我尝试在 Store 中设置新的 url。 这是我的商店:

Ext.define('Application.store.DetailStore', {
extend: 'Ext.data.Store',

config: {
    model: 'Application.model.DetailModel',
    autoLoad :true,
    sorters: 'title',
    grouper : function(record) {
        return record.get('title')[0];
        },

   proxy: {
    type: 'ajax',
    url : '/data/data1.php',
   reader: {
   type: 'json',
  rootProperty:'recipes'}
         } 
}

});

这是我在 NestedList 中的leafitemtap 监听器:

onLeafItemTap: function(nestedList, list, index, node, record, e) {
    filter = record.get('text');
    var detailCard = nestedList.getDetailCard();       
    Ext.getStore('Application.store.DetailStore').getProxy().setUrl('/data/data2.php');
    Ext.getStore('Application.store.DetailStore').load()
}

在此之后我无法点击叶子项目并且详细卡不显示。 有谁知道可能出了什么问题?

【问题讨论】:

    标签: sencha-touch extjs sencha-touch-2


    【解决方案1】:

    下面我使用getMain方法将detailCard推送到列表顶部,当点击叶子项目并加载商店时。我还假设您正在使用 getMain 作为参考在控制器中定义 Leafitemtap 逻辑。

    您也可以使用 storeId 代替“Application.store.DetailStore”

            Ext.getStore('Application.store.DetailStore').setProxy({
            type: 'ajax',
            url: '/data/data2.php'
        }).load({
            callback: function(records, operations, success) {
                if (success = true) {
                    this.getMain().push({
                        xtype: 'detailsCard',
                        data: record.getData()
                    })
                } else {
                    Ext.Msg.alert('Error', 'Something went wrong!', Ext.emptyFn);
                }
            },
            scope: this
        });
    

    【讨论】:

    • 如果您想要做的只是设置并加载存储,请阅读问题:Ext.getStore('Application.store.DetailStore').setProxy({ type: 'ajax', url: '/data/data2.php'}).load() 而不是使用 getProxy 和 setUrl
    • 感谢您的回复!但这无济于事,我仍然无法点击叶子项目。我测试删除了部分代码,当我在 Ext.getStore('Application.store.DetailStore') 之后写一些东西时它停止工作
    • 您可以发布 NestedList 视图、模型和您从商店获取的 JSON 吗?
    • 很抱歉打扰您,我知道使用不同的 url 是不对的,我必须过滤我的商店。感谢您的宝贵时间!
    猜你喜欢
    • 2018-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-04
    • 2013-04-23
    • 1970-01-01
    • 2015-04-18
    相关资源
    最近更新 更多