【问题标题】:In extjs How to change URL to set city name dynamically在 extjs 如何更改 URL 以动态设置城市名称
【发布时间】:2013-04-13 17:26:51
【问题描述】:

我在 extjs 工作。我正在寻找给定城市的天气信息功能。所以在 extjs4 控制器中我有代码-

getWeather : function() {
        $obj = 'pune';
        Ext.require('Ext.data.JsonP', function() {
            Ext.data.JsonP.request({
                url : "http://api.wunderground.com/api/4ab310c7d75542f3/geolookup/conditions/q/IA/pune.json",
                success : function(parsed_json) {
                    var location = parsed_json['location']['city'];
                    var temp_c = parsed_json['current_observation']['temperature_string'];
                    alert("Current temperature in " + location + " is: "
                            + temp_c);
                }
            });
        });
    },

它工作正常。但在上面的函数中,我想动态设置城市名称。假设我有变量 $cityname=pune。然后使用这个变量我需要如何修改 URL-“http://api.wunderground.com/api/4ab310c7d75542f3/geolookup/conditions/q/IA/pune.json”,这样如果天气信息将根据该变量所具有的城市名称被检索。那么如何更改 URL 以动态设置城市名称

【问题讨论】:

    标签: url extjs4 weather


    【解决方案1】:

    使用传递给请求方法的 params 对象: http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.data.JsonP-method-request

    示例:

    Ext.data.JsonP.request({
         url : "http://api.wunderground.com/api/..",
         success : function(response) { ...},
         params:{foo:'bar'}
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-21
      • 1970-01-01
      • 1970-01-01
      • 2018-06-02
      • 1970-01-01
      相关资源
      最近更新 更多