小编dav*_*vin的帖子

node.js process.nextTick错误

我在使用node.js遇到一些奇怪的事情:

当我尝试使用仅包含以下代码的http客户端时:

require('http').get({host:'127.0.0.1',port:9000, path:'/'}, function(res){
    var data = '';
    res.setEncoding('utf8');
    res.on('data', function(chunk){
        data += chunk; 
    });
    res.on('end', function(){
        console.log(data);
    });
});
Run Code Online (Sandbox Code Playgroud)

抛出错误:

node.js:116
        throw e; // process.nextTick error, or 'error' event on first tick
        ^ TypeError: Cannot call method 'emit' of undefined
    at Socket.<anonymous> (http.js:1174:9)
    at Socket.emit (events.js:42:17)
    at Array.<anonymous> (net.js:799:27)
    at EventEmitter._tickCallback (node.js:108:26)
Run Code Online (Sandbox Code Playgroud)

当我在浏览器中浏览到127.0.0.1:9000时,我得到了所需的网页.此外,在Web主机日志中,我可以看到已经有一个成功的连接(如果我使用的话就不会发生这种情况,比如说,localhost而不是127.0.0.1.只是旁边).

我说这很有趣,因为如果我将主机更改为谷歌或者什么都可以正常工作,它会将html吐出到控制台.

我应该注意,我在cygwin下运行节点0.4.2,从源代码构建.

以前见过/处理过这个的人?

node.js

16
推荐指数
1
解决办法
1万
查看次数

断开连接时Socket.io重新连接?

这样的事情可能吗?

socket.on('disconnect', function(){
    console.log('disconnected...');
    socket.connect();
    socket.on('connect', function(){
    console.log('...reconnected');
    })  
})
Run Code Online (Sandbox Code Playgroud)

javascript node.js socket.io

5
推荐指数
1
解决办法
4382
查看次数

如何测试List <String>的空或null?

似乎无论我做什么,我得到了错误的结果.

我的清单定义如下:

private List<String> selectedPriorities;
Run Code Online (Sandbox Code Playgroud)

getter/setter没什么奇怪的或花哨的:

public void setSelectedPriorities(List<String> selectedPriorities) {
    this.selectedPriorities = selectedPriorities;
}

public List<String> getSelectedPriorities() {
    return selectedPriorities;
}
Run Code Online (Sandbox Code Playgroud)

在会话bean中,我想根据此列表的内容(或缺少内容)更改不同的列表.

这是代码:

List<String> restrictList = new ArrayList<String>();
restrictList.add("lower(logs.clazz) like lower(concat(#{logs.clazz},'%'))");
restrictList.add("lower(logs.rule) like lower(concat(#{logs.rule},'%'))");
PrioritySelectorBean selectorBean = (PrioritySelectorBean) Component.getInstance("prioritySelectorBean",true);
System.out.println("constructRestrictionList selectorBean "+selectorBean.getSelectedPriorities());

if (selectorBean.getSelectedPriorities() == null) {
    System.out.println("IS NULL");
    return restrictList;
}

if (selectorBean.getSelectedPriorities().isEmpty()){
    System.out.println("IS EMPTY");
}

if (selectorBean.getSelectedPriorities().size()<1){
    System.out.println("HAS NOTHING IN IT");
    return restrictList;
}
System.out.println("NOT NULL");
restrictList.add("lower(logs.priority) in (#{prioritySelectorBean.selectedPriorities})");
Run Code Online (Sandbox Code Playgroud)

它总是落到NOT NULL并将字符串添加到restrictList.它让我疯了!如何在此列表中检测到虚无?这是日志片段

14:24:10,057 INFO  [STDOUT] constructRestrictionList selectorBean [] …
Run Code Online (Sandbox Code Playgroud)

java

4
推荐指数
1
解决办法
3万
查看次数

如何在没有javascript的情况下停止CSS动画

这是jsFiddle.我想要的是当它达到最终位置时停止盒子.我知道还有一个转换功能,但似乎不起作用.所有动画功能类型是否也可用于过渡?我在实际工作中使用旋转功能.

javascript animation transition css3

2
推荐指数
1
解决办法
2140
查看次数

画布绘图错误

当我尝试将图像绘制到Canvas元素时,我得到了这个例外:

未捕获错误:INDEX_SIZE_ERR:DOM异常1
textureLoadedstaticsprite.js:14
StaticSpritestaticsprite.js:21
(匿名函数)

CanvasRenderingContent和HTMLImageElement都存在.我只是不明白:S

这是我正在使用的代码:

    /**
  * Class for drawing static sprites, like trees and blocks
  */

function StaticSprite(args) {

    // Private Fields
    var texture = new Image();

    // Events
    function textureLoaded(context) {
        console.log(context);
        console.log(texture);
        context.drawImage(texture, 0, 0, 32, 32);

    }

    // Constructor

    // Add event listeners
    texture.addEventListener("load", textureLoaded(this.graphics), false);

    // Load texture
    texture.src = "img/assets/wall1.png";

    if(args != undefined) {

        // Set local fields
        this.x = args.x || this.x;
        this.y = args.y || this.y;
        this.z = args.z || …
Run Code Online (Sandbox Code Playgroud)

javascript image drawimage html5-canvas

0
推荐指数
1
解决办法
309
查看次数