事实上,我曾尝试过,但失败了。现在代码是:
function include(path){
var a=document.createElement("script");
a.type = "text/javascript";
a.src=path;
var head=document.getElementsByTagName("head")[0];
head.appendChild(a);
}
include("app/controller/node_modules/socket.io-client/dist/socket.io.js");
Ext.define('WGTalk.controller.guest', {
extend: 'Ext.app.Controller',
config:{
refs:{
viewMsg:'#viewMsg',
txtMsg:'#txtMsg'
},
control:{
'#btSend':{
tap:'doSend'
}
}
},
launch:function(){
var socket = io.connect('http://localhost:8080');
socket.on('connect',function(){
console.log("connected server");
});
socket.on('disconnect',function(){
console.log("server closed");
});
socket.on('message',function(data) {
console.log('Received a message from the server: ',data);
});
},
doSend:function(){
var msg = this.getTxtMsg().getValue();
var msgStore = this.getViewMsg().getStore();
msgStore.add({name:msg,age:'180'});
this.getTxtMsg().setValue("");
}
});
错误是:*ReferenceError: Can't find variable: io @"var socket = io.connect('http://localhost:8080'); " *
我该如何解决这个错误?