Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.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
Javascript meteor在onrendered模板内调用jquery_Javascript_Jquery_Templates_Meteor - Fatal编程技术网

Javascript meteor在onrendered模板内调用jquery

Javascript meteor在onrendered模板内调用jquery,javascript,jquery,templates,meteor,Javascript,Jquery,Templates,Meteor,我想在模板上的onRendered函数中包含一个使用jquery的脚本 这是密码 Template.Admin_users.onRendered(function(){ var instance = this; instance.autorun(function(){ if($){ console.log($); console.log("jquery"); $("#Users.collect

我想在模板上的
onRendered
函数中包含一个使用
jquery
的脚本

这是密码

Template.Admin_users.onRendered(function(){
    var instance = this;
    instance.autorun(function(){
        if($){
            console.log($);
            console.log("jquery");
            $("#Users.collection-item").click();    
            $.getScript(
                "http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"
                //'https://maps.googleapis.com/maps/api/js?libraries=places'
                , function(){
                    console.log("loaded gmap");
                    var acs = $(".citycomplete").length;
                    for(var i = 0 ;i<acs;i++){
                        var autocomplete = new google.maps.places.Autocomplete($(".citycomplete")[i], {});
                        autocomplete.id = $(".citycomplete")[i].id;
                        google.maps.event.addListener(autocomplete, 'place_changed', function() {
                            var place = autocomplete.getPlace();
                            $("input[name=lat]#"+autocomplete.id).val(place.geometry.location.lat());
                            $("input[name=lng]#"+autocomplete.id).val(place.geometry.location.lng());
                        });
                    }
            });
        }
    });

});
Template.Admin\u users.onRendered(函数(){
var实例=这个;
autorun(函数(){
如果(美元){
console.log($);
console.log(“jquery”);
$(“#Users.collection item”)。单击();
$.getScript(
"http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"
//'https://maps.googleapis.com/maps/api/js?libraries=places'
,函数(){
日志(“加载的gmap”);
var acs=$(“.citycomplete”).length;

对于(var i=0;i)

如果没有触发重新运行的反应变量,则无需将该代码放入自动运行中。此外,您也不希望它多次正确运行?如果是这样,请删除自动运行。您可以做的是等待一段时间

Template.Admin_users.onRendered(function(){
    Meteor.setTimeout(()=>{doYourThing()}, 500);
});

这有帮助吗?

是的。这很有效。即使没有等待500毫秒Meteor.setTimeout(()=>{doYourThing()},0);奇怪的是,
Meteor.defer
解决方案当时对您不起作用,bc这只是setTimeout的一个方便函数,没有延迟。无论如何,很高兴我能提供帮助。