1

我正在创建一个高度依赖地理位置的应用程序。我在 app.js 中有变量 'GeoApp.app.geoLat' 和 GeoApp.app.geoLong' 是用地理坐标设置的。

如果我在任何视图中使用 console.out,访问和输出值都没有问题。在商店中,这些值是空的,好像它没有访问权限,或者变量可能尚未定义或存在。

实现我想要做的最佳实践是什么?

Ext.define('GeoApp.store.Places', {
    extend:'Ext.data.Store',

    config: {
        model:'GeoApp.model.Place',
        autoLoad:'true',
        proxy: {
            type:'ajax',
            url:'googleapiurl/json?location=' + GeoApp.app.geoLat + ','+ GeoApp.app.geoLong + '&radius=500...',
            reader: {
                type:'json',
                rootProperty:'results'
            }
        }*/
    }
})
4

2 回答 2

1

那是因为您的商店是在您的应用程序启动时创建的,您的 url 字符串也是如此。因此,当您启动应用程序时GeoApp.app.geoLatGeoApp.app.geoLong它们为 null 或未定义,它们不会出现在您的 url 中。

我要做的是将url设置为googleapiurl/json?radiu=500...,然后将location参数添加为extraParam代理,如下所示:

Ext.getStore('Places').getProxy().setExtraParams({
  location: GeoApp.app.geoLat + ',' + GeoApp.app.geoLong
});

希望这有帮助

于 2012-11-20T20:49:52.917 回答
0

您可以做的是在加载商店之前设置代理 url。因此,您必须设置autoLoadfalse. show()例如,您可以在视图组件的功能中使用下面的代码。

show: function(component, options){
    var store = Ext.getStore('Places');

    store.setProxy({
       url:'googleapiurl/json?location=' + GeoApp.app.geoLat + ','+ GeoApp.app.geoLong + '&radius=500...',
    });

    store.load();
}

祝你好运!

于 2012-11-20T21:26:48.273 回答