在我的meteor应用程序中,我正在使用一个需要查询的引导程序表。 我运行了“meteor add query”,它列在“packages”文件中:
# 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();
})
当我从app根目录运行meteor命令时,出现以下错误:
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.
我该怎么做才能解决这个问题?
答案 0 :(得分:1)
jQuery是一个仅限客户端的库,您不能在服务器端使用它 - 抛出此错误是因为jQuery
未定义。要解决此问题,请将代码限制在客户端,方法是将其放在/client
文件夹中(或/client/lib
,如果您希望它在加载时具有优先级),或者将代码包装在
if (Meteor.isClient) {
...
}