【问题标题】:Sencha Touch dynamic store URL on clickSencha Touch 动态商店 URL 点击
【发布时间】:2012-01-09 21:04:28
【问题描述】:

我希望我在 Sencha touch 中的商店加载不同的 PHP 文件,具体取决于单击了轮播中的哪个项目。我的轮播中的每个项目都分配了 itemid: {number}。这是我现在的商店:

var store = new Ext.data.Store({
        model: 'One',
        proxy: {
            type: 'ajax',
            url: '/carousel2store/Carousel 2_files/get-album.php',
            reader: {
                type: 'json',
                root: 'albums'
            }
        },....etc

我尝试过像这样改变商店,它给出“/carousel2store/Carousel 2_files/get-album2.php”,但我想让数字 2 动态化,所以点击时它会改变:

var store = new Ext.data.Store({
        model: 'One',
        proxy: {
            type: 'ajax',
            url: '/carousel2store/Carousel 2_files/get-album' + '2' +'.php',
            reader: {
                type: 'json',
                root: 'albums'
            }
        },

我已尝试添加 itemid

url: '/carousel2store/Carousel 2_files/get-album' + '{itemid}' +'.php', and
url: '/carousel2store/Carousel 2_files/get-album' + '{data.itemid}' +'.php',

但到目前为止我还没有运气。 sencha 论坛上一位非常乐于助人的人建议我试试这个:

var store = new Ext.data.Store({
        model: 'One',
        proxy: {
            type: 'ajax',
            url: '/carousel2store/Carousel 2_files/get-album{itemId}.php',
            reader: {
                type: 'json',
                root: 'albums'
            }
        }
    });

    store.proxy.url = store.proxy.url.replace('{itemId}', 1);

    console.log(store);

...但是当我用鼠标单击时,我无法让它在我的测试中工作,我认为因为它已经在轮播和项目点击侦听器之前加载了商店(至少它对我不起作用我用鼠标测试)。我想我需要一种在商品点击后立即强制更新商店名称的方法。

提前致谢

:-)

【问题讨论】:

    标签: url dynamic sencha-touch store carousel


    【解决方案1】:

    我遇到了一个类似的问题,我需要动态更改代理上的 URL。我发现这在大多数情况下特别有效,只要确保正确处理加载顺序即可。

    store = Ext.StoreMgr.get('YourStore');
    store.setProxy({
        type: 'ajax',
        url: 'http://www.yoururl.com?foo=bar',
    });
    

    【讨论】:

    【解决方案2】:

    M69 的解决方法很棒!

    通过beforeload监听器集成到商店定义中:

    Ext.define('MyApp.store.Accounts', {
        extend: 'Ext.data.TreeStore',
    
        config: {
            autoLoad: false,
    
            model: 'MyApp.model.Account',
    
            scope: this,
    
            listeners: {
                beforeload: function(store){
                    store.setProxy({
                        type: 'ajax',
                        url: MyApp.getUrl('accounts', {token:MyApp.getToken()}),
                        reader: {
                            type: 'json',
                            rootProperty: 'response.accounts'
                        }
                    });
                }
            }
        }
    });
    

    【讨论】:

    • 嗨,Thomas,在所有解决方案中,我最喜欢你的解决方案。你能解释一下这个方法的参数:getUrl(parameter1,parameter2)吗?我不明白什么是第一个和第二个参数及其类型。
    • 嗨 Franva,该方法只是一个内部帮助器,用于根据请求的页面和提供的标题返回 URL。您只需要在那里传递 URL。
    【解决方案3】:

    我和你有同样的问题,我通过以下方式解决了:

    store.getProxy().url = './getnotes?folderName=' + folderName;
    store.load();
    

    我在定义store的时候没有在proxy中设置url,把autoLoad设置为false。

    【讨论】:

      【解决方案4】:

      我希望这应该可行.....

      var str = Ext.data.StoreManager.lookup('myStoreId');
      str.setProxy({
      type: 'ajax',
      url: 'URL1',
      });
      

      【讨论】:

        【解决方案5】:

        我成功地使用了这个。即将url传递给加载操作:

        var aStore = this.getMyStore(),
            url = 'data/assertions.php';
        
        aStore.load({
            url: url,
            callback: function (records, operation, success) {
                console.log(records);
            },
            scope: this
        })
        

        【讨论】:

          猜你喜欢
          • 2012-05-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-06-17
          • 2011-09-01
          • 2014-03-03
          • 2014-01-25
          • 2015-12-28
          相关资源
          最近更新 更多