我需要对IE使用jsonp-polling,对Firefox使用xhr-polling,所以我尝试在客户端定义传输类型,如下所示:
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
var socket = io.connect(VG.NODE_SERVER_URL,{
transports:['xhr-polling']
});
} else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
var socket = io.connect(VG.NODE_SERVER_URL,{
transports:['jsonp-polling']
});
} else {
var socket = io.connect(VG.NODE_SERVER_URL);
}
Run Code Online (Sandbox Code Playgroud)
我在Firefox上测试了它,并在socket.io-client lib上添加了日志.在
https://github.com/LearnBoost/socket.io-client/blob/master/dist/socket.io.js#L1509
option.transports是["xhr-polling", "flashsocket", "htmlfile",
"xhr-polling", "jsonp-polling"],这是对的.但是,在
https://github.com/LearnBoost/socket.io-client/blob/master/dist/socket.io.js#L1679
我不知道为什么传输会改变["htmlfile", "jsonp-
polling", "xhr-polling"],它与我在服务器端定义的顺序相同.
为什么不使用之前的选项?
我通过以下方式测试了Django的"pre_save"信号,但无法捕获其中任何一个的信号.
$
from django.db.models.signals import pre_save
import logging
def my_callback(sender, **kwargs):
logging.debug("======================================")
pre_save.connect(my_callback)
Run Code Online (Sandbox Code Playgroud)
在manage.py shell中运行上面的代码:然后我运行我的网站并看到models.save()成功运行,但回调函数没有运行.
或者,我再次在shell上运行上面的代码,然后在shell中运行models.save()."save"再次运行良好,但回调函数仍未发生任何变化.
最后,我将上面的代码嵌入到一个__init__.py文件中,然后在网站上运行save()函数.但事实并非如此.
你能不能帮我弄清楚为什么pre_save信号看起来不起作用?
我正在考虑使用JavaScript对象作为字典.
var dict = {}
dict['a'] = 1;
dict['b'] = 2;
var my_first = dict['a'];
Run Code Online (Sandbox Code Playgroud)
我不清楚这种实施的时间复杂性.是哈希吗?谢谢.
在Django中,我捕获pre_save信号的代码效果很好.但是,在tests.py中的测试用例中,信号处理程序无法接收任何内容.这个问题有什么暗示吗?
django ×2
python ×2
dictionary ×1
hash ×1
hashmap ×1
javascript ×1
node.js ×1
socket.io ×1
unit-testing ×1