【问题标题】:meteor app - unable to find query流星应用程序 - 无法找到查询
【发布时间】:2014-04-08 03:45:46
【问题描述】:

在我的流星应用程序中,我使用了一个需要查询的引导表。 我跑了“流星添加查询”,它列在“包”文件中:

# Meteor packages used by this project, one per line.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.

standard-app-packages
autopublish
insecure
reactive-dict
bootstrap
js-base-model
jquery
iron-router

文件(table.js)位于/lib下:

(function(){
    'use strict';
    var $ = jQuery;
    $.fn.extend({
        filterTable: function(){
            return this.each(function(){
                $(this).on('keyup', function(e){
                    $('.filterTable_no_results').remove();
                    var $this = $(this), search = $this.val().toLowerCase(), target = $this.attr('data-filters'), $target = $(target), $rows = $target.find('tbody tr');
                    if(search == '') {
                        $rows.show(); 
                    } else {
                        $rows.each(function(){
                            var $this = $(this);
                            $this.text().toLowerCase().indexOf(search) === -1 ? $this.hide() : $this.show();
                        })
                        if($target.find('tbody tr:visible').size() === 0) {
                            var col_count = $target.find('tr').first().find('td').size();
                            var no_results = $('<tr class="filterTable_no_results"><td colspan="'+col_count+'">No results found</td></tr>')
                            $target.find('tbody').append(no_results);
                        }
                    }
                });
            });
        }
    });
    $('[data-action="filter"]').filterTable(); 
})(jQuery);

$(function(){
    // attach table filter plugin to inputs
    $('[data-action="filter"]').filterTable();

    $('.container').on('click', '.panel-heading span.filter', function(e){
        var $this = $(this), 
                $panel = $this.parents('.panel');

        $panel.find('.panel-body').slideToggle();
        if($this.css('display') != 'none') {
            $panel.find('.panel-body input').focus();
        }
    });
    $('[data-toggle="tooltip"]').tooltip();
})

当我从应用程序根目录运行流星命令时,我收到以下错误:

Eugenes-MacBook-Pro-3:wizard eugene$ meteor
[[[[[ ~/Documents/DevTraining/meteor/wizard ]]]]]

=> Started proxy.
=> Started MongoDB.     
W20140407-22:43:54.117(-5)? (STDERR) 
W20140407-22:43:54.153(-5)? (STDERR) /Users/eugene/Documents/DevTraining/meteor/wizard/.meteor/local/build/programs/server/boot.js:186
W20140407-22:43:54.154(-5)? (STDERR) }).run();
W20140407-22:43:54.154(-5)? (STDERR)    ^
W20140407-22:43:54.154(-5)? (STDERR) ReferenceError: jQuery is not defined
W20140407-22:43:54.154(-5)? (STDERR)     at app/lib/table.js:28:4
W20140407-22:43:54.155(-5)? (STDERR)     at app/lib/table.js:46:3
W20140407-22:43:54.155(-5)? (STDERR)     at /Users/eugene/Documents/DevTraining/meteor/wizard/.meteor/local/build/programs/server/boot.js:155:10
W20140407-22:43:54.155(-5)? (STDERR)     at Array.forEach (native)
W20140407-22:43:54.155(-5)? (STDERR)     at Function._.each._.forEach (/Users/eugene/.meteor/tools/c2a0453c51/lib/node_modules/underscore/underscore.js:79:11)
W20140407-22:43:54.155(-5)? (STDERR)     at /Users/eugene/Documents/DevTraining/meteor/wizard/.meteor/local/build/programs/server/boot.js:82:5
=> Exited with code: 8
W20140407-22:43:54.803(-5)? (STDERR) 
W20140407-22:43:54.803(-5)? (STDERR) /Users/eugene/Documents/DevTraining/meteor/wizard/.meteor/local/build/programs/server/boot.js:186
W20140407-22:43:54.803(-5)? (STDERR) }).run();
W20140407-22:43:54.803(-5)? (STDERR)    ^
W20140407-22:43:54.806(-5)? (STDERR) ReferenceError: jQuery is not defined
W20140407-22:43:54.806(-5)? (STDERR)     at app/lib/table.js:28:4
W20140407-22:43:54.806(-5)? (STDERR)     at app/lib/table.js:46:3
W20140407-22:43:54.806(-5)? (STDERR)     at /Users/eugene/Documents/DevTraining/meteor/wizard/.meteor/local/build/programs/server/boot.js:155:10
W20140407-22:43:54.806(-5)? (STDERR)     at Array.forEach (native)
W20140407-22:43:54.806(-5)? (STDERR)     at Function._.each._.forEach (/Users/eugene/.meteor/tools/c2a0453c51/lib/node_modules/underscore/underscore.js:79:11)
W20140407-22:43:54.806(-5)? (STDERR)     at /Users/eugene/Documents/DevTraining/meteor/wizard/.meteor/local/build/programs/server/boot.js:82:5
=> Exited with code: 8
W20140407-22:43:55.496(-5)? (STDERR) 
W20140407-22:43:55.496(-5)? (STDERR) /Users/eugene/Documents/DevTraining/meteor/wizard/.meteor/local/build/programs/server/boot.js:186
W20140407-22:43:55.497(-5)? (STDERR) }).run();
W20140407-22:43:55.497(-5)? (STDERR)    ^
W20140407-22:43:55.499(-5)? (STDERR) ReferenceError: jQuery is not defined
W20140407-22:43:55.499(-5)? (STDERR)     at app/lib/table.js:28:4
W20140407-22:43:55.499(-5)? (STDERR)     at app/lib/table.js:46:3
W20140407-22:43:55.499(-5)? (STDERR)     at /Users/eugene/Documents/DevTraining/meteor/wizard/.meteor/local/build/programs/server/boot.js:155:10
W20140407-22:43:55.499(-5)? (STDERR)     at Array.forEach (native)
W20140407-22:43:55.499(-5)? (STDERR)     at Function._.each._.forEach (/Users/eugene/.meteor/tools/c2a0453c51/lib/node_modules/underscore/underscore.js:79:11)
W20140407-22:43:55.500(-5)? (STDERR)     at /Users/eugene/Documents/DevTraining/meteor/wizard/.meteor/local/build/programs/server/boot.js:82:5
=> Exited with code: 8
=> Your application is crashing. Waiting for file change.

我能做些什么来解决这个问题?

【问题讨论】:

    标签: meteor


    【解决方案1】:

    jQuery 是一个仅限客户端的库,您不能在服务器端使用它 – 抛出此错误是因为 jQuery 未在此处定义。要修复它,请将您的代码限制在客户端,方法是将其放置在 /client 文件夹中(或 /client/lib,如果您希望它在加载时具有优先权),或者将代码包装在

    if (Meteor.isClient) {
      ...
    }
    

    【讨论】:

      猜你喜欢
      • 2014-12-18
      • 2016-08-24
      • 2016-08-09
      • 1970-01-01
      • 1970-01-01
      • 2019-06-17
      • 2013-07-28
      • 2015-04-27
      • 1970-01-01
      相关资源
      最近更新 更多