Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在extjs4中集成jquery代码_Jquery_Extjs4_Weather - Fatal编程技术网

如何在extjs4中集成jquery代码

如何在extjs4中集成jquery代码,jquery,extjs4,weather,Jquery,Extjs4,Weather,我在extjs工作。我想找到特定城市的天气。我从“”中获得了引用。它通过在html文件中编写以下代码,以json格式提供与给定城市相关的所有信息- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"> </script> <script> jQuery(document).ready(function($) {

我在extjs工作。我想找到特定城市的天气。我从“”中获得了引用。它通过在html文件中编写以下代码,以json格式提供与给定城市相关的所有信息-

   <script
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js">

</script>

<script>
    jQuery(document).ready(function($) {
                        $.ajax({
                                    url : "http://api.wunderground.com/api/4ab310c7d75542f3/geolookup/conditions/q/IA/Pune.json",
                                    dataType : "jsonp",
                                    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);
                                    }
                                });
                    });
</script>

jQuery(文档).ready(函数($){
$.ajax({
url:“http://api.wunderground.com/api/4ab310c7d75542f3/geolookup/conditions/q/IA/Pune.json",
数据类型:“jsonp”,
成功:函数(已解析的_json){
var location=parsed_json['location']['city'];
var temp_c=parsed_json['current_observation']['temperature_string'];
警报(“当前温度在”
+位置+”为:“+temp_c”;
}
});
});

它工作正常。现在我想将这个jquery代码集成到extjs的控制器中。那么,有人能指导我如何在extjs中集成上述jquery代码吗

下面的extjs代码与您的代码相同,因此您可以在控制器内部使用它

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);
    }
});

ExtJS和jQuery之间没有冲突(两者都有自己的名称空间)。只要jQuery在app.js之前加载,就可以在ExtJS控制器中使用jQuery。自从ExtJS 4.x以来,我就在ExtJS中使用jQuery,从来没有出现过任何问题。

在sencha touch和ExtJS中,所有javascript代码都将放在app.js文件或其他类js文件中。您永远不会将这样的代码放在html中的脚本标记中。如果你想在你的应用程序加载之前或者第一件事之前打电话到那个位置,你可以把它放在你的应用程序启动功能中或者直接放在上面

//DO YOUR AJAX CALL HERE BEFORE YOUR APPLICATION LAUNCHES

    Ext.application({
        name: 'MyApp',
        launch: function() {

            //OR INSIDE THE LAUNCH FUNCTION
        }
    });

谢谢你的回复,先生。我已经在控制器中包含了上面的代码,但它给我的错误是——“TypeError:Ext.data.JsonP未定义”,所以我需要做什么更改?在使用它之前,你应该先加载,然后加载你可以用作示例的类。require('Ext.data.JsonP',function(){/*您的代码*/});谢谢你的答复,先生……它起作用了。。我想再问一件事。如何动态更改城市名称。i、 假设我有一个存储城市名称的变量。那么如何更改url-“”以便城市名称将被该变量替换。我们将根据变量所包含的城市名称获取城市信息。请引导mevar city=“Pune”。。。请求({url:+city+“.json”…});