首页 > 解决方案 > 来自 Tracker 重新计算函数的异常:ReferenceError: $el is not defined

问题描述

尝试过滤某个用户发布的图像时出现以下错误:

Exception from Tracker recompute function:
meteor.js?hash=857dafb4b9dff17e29ed8498a22ea5b1a3d6b41d:1059 ReferenceError: $el is not defined
    at destroyApi (stars_rating.js:98)
    at Blaze.TemplateInstance.Template.starsRating.destroyed (stars_rating.js:132)
    at template.js:124
    at Function.Template._withTemplateInstanceFunc (template.js:493)
    at fireCallbacks (template.js:120)
    at Blaze.View.<anonymous> (template.js:226)
    at fireCallbacks (view.js:276)
    at Object.Tracker.nonreactive (tracker.js:603)
    at view.js:273
    at Object.Blaze._withCurrentView (view.js:533)

在这里找到我点击用户名时写的js点击事件:

'click .js-set-image-filter': function(event){
        Session.set("userFilter", this.createdBy);
    }

在这里找到模板帮助代码:

images: function(){
    
    if(Session.get("userFilter")){
        return TasksCollection.find({createdBy:Session.get("userFilter")},{sort :{cretedOn:-1 ,rating:-1}});
    }
    else{
        return TasksCollection.find({},{sort :{cretedOn:-1 ,rating:-1}});
    }
},

在这里找到模板代码:

<template name="hello"> 
    {{#if currentUser}}
    <button class="js-show-image-form btn btn-success">show</button>
    {{/if}}
    <div class="row">
        {{#each images}}
        <div class="col-xs-6 col-md-3" id="{{_id}}">
            <div class="thumbnail">
                <img class="js-image crop-img" src="{{img_src}}" alt="{{imd_alt}}"/>
                <div class="caption">
                    <h3>Rating : {{rating}}</h3>
                    <p>{{imd_alt}}</p>
                    <p> User: 
                        <a href="#" class="js-set-image-filter"> {{getUser createdBy}} </a>
                    </p>
                    <p> {{>starsRating mutable=true class="js-rate-image" id=_id}}</p>
                    <button class="js-del-image btn btn-warning">Delete</button>
                </div>
            </div>
        </div>
        {{/each}}
    </div>
</template>

标签: javascriptjquerymeteor-blazespacebars

解决方案


我已经弄清楚了一半,但我不确定如何完全解决它。Tracker 错误的异常是由在 <a href="" class="js-set-image-filter">{{getUser createdBy}} . Now 的 href 中使用“#”引起的,当我单击用户时,我的页面会闪烁并重置为所有图像,这似乎完全是另一个问题。


推荐阅读