流星客户端外部Javascript文件问题
Meteor Client Side External Javascript File issues
我正在玩pubnub和Meteor,我指的是客户端外部js文件和接收错误。
我的代码如下。服务器端工作正常,但是客户端接收到错误。"未捕获的TypeError: Cannot read property '$' of undefined"
我在nodejs中工作得很好,但想让它在流星中工作。我一直在为这个烦恼,谢谢。
if (Meteor.isClient) {
// counter starts at 0
Session.setDefault('counter', 0);
Template.hello.helpers({
counter: function () {
return Session.get('counter');
}
});
Template.hello.events({
'click button': function () {
// increment the counter when button is clicked
Session.set('counter', Session.get('counter') + 1);
}
});
Template.hello.rendered = function(){
$.getScript("http://cdn.pubnub.com/pubnub.min.js", function() {
//callbcak function
(function(){
var output = PUBNUB.$('output');
PUBNUB.subscribe({
channel: 'my_channel',
callback: function(message){
output.innerHTML += message;
}
})
})();
})
};
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
var PUBNUB = Meteor.require('pubnub').init({});
setInterval(function() {
PUBNUB.publish({
channel: 'my_channel',
message: 'hello SMB'
});
}, 1000);
}
看起来您还没有初始化实例!
var pubnub = PUBNUB({
subscribe_key: 'your-sub-key',
publish_key: 'your-pub-key'
});
,
pubnub.subscribe({...
相关文章:
- 关于引入外部javascript文件的问题&css通过https
- Javascript,文件输入和FormData问题
- Node.js服务器问题-已添加“/"在浏览器中查找文件时
- Express Routes-多个文件的问题
- 使用ajax在html中加载html文件时出现的问题
- 尝试从csv文件中检索单个值时出现问题
- 在javascript中检查文件扩展名的问题
- 加载本地json文件问题
- 外部JavaScript文件问题
- Java 程序文本文件问题
- Django + skelJS / 静态文件问题 / 对 CSS 中图像的引用
- 获取 JSON 文件问题
- Wordpress-自定义页面包括第二个导致函数文件问题的自定义页面
- 外部js文件问题
- 加载javascript文件问题
- JS prototype.namespace单独的文件问题
- 将bootstrap主题安装到Rails 4应用程序中- javascript文件问题
- AngularJS图表文件问题
- 流星客户端外部Javascript文件问题
- Javascript类方法加载json文件问题