2013-04-23 51 views
2

我正在使用extjs4。我正在研究天氣模塊。我正在藉助控制器代碼重新獲取天氣信息 -在extjs中如何在視圖中顯示變量?

getWeather : function() { 
     var getdata=this.getipaddress(); 
     console.log(getdata); 
     var city = "pune"; 
     var urllink="http://api.wunderground.com/api/4ab310c7d75542f3/geolookup/conditions/q/IA/" + city + ".json"; 
     console.log(urllink); 
     Ext.require('Ext.data.JsonP', function() { 
      Ext.data.JsonP.request({ 
       //url : "http://api.wunderground.com/api/4ab310c7d75542f3/geolookup/conditions/q/IA/pune.json", 
       url:urllink, 
       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); 
          return temp_c; 

       var viewObj=Ext.create('Balaee.view.sn.user.weather'); 
       var viewObj.show(); 
       } 
      }); 
     }); 
    }, 

現在我想在視圖中顯示此temp_c變量的值和城市。我有這兩個變量直接。我沒有任何商店相關它。假設我有查看爲 -

Ext.define('Balaee.view.sn.user.weather', 
{ 
     extend:'Ext.view.View', 
     id:'weatherId', 
     alias:'widget.weatherView', 
     config: 
     { 
      tpl:'<tpl for=".">'+ 
       '<div id="main">'+ 
       '</br>'+      
       '<b>City :- </b> {city} </br>'+ 
       '<b>Temp:- </b> {temp_c} </br>'+ 

       '</div>'+ 
       '</tpl>', 
      itemSelector:'div.main',} 

}); 但上面的視圖不顯示任何值。那麼如何在視圖中顯示這些變量?

回答

2

可以渲染模板,Ext.container.Container(Ext.view.View是沒有必要的,如果你沒有從商店) 這裏是你的情況下,例如:

Ext.define('Balaee.view.sn.user.weather',{ 
    extends:'Ext.container.Container', 
    alias:'widget.weatherView', 
    tpl:Ext.create('Ext.XTemplate', 
     '<div id="main"></br>', 
      '<b>City :- </b> {city} </br>', 
      '<b>Temp:- </b> {temp_c} </br>', 
     '</div>') 
}); 

然後Ajax響應可以這樣稱呼它:

var viewObj=Ext.create('Balaee.view.sn.user.weather',{ 
    renderTo:'IdOfYourRenderingArea' // Or it can be Ext.getBody() 
}); 
viewObj.update({city:location, temp_c:temp_c}); 

如果你想渲染與數據視圖然後你需要存儲和模型。

+0

thanx先生...其工作... – user1722857 2013-04-23 09:38:00

+0

我很高興它幫助你 – XenoN 2013-04-23 14:34:57