错误无法将undefined或null转换为object

时间:2017-10-29 04:40:34

标签: javascript node.js

这里的代码我最近无法启动代码导致错误,无法将undefined或null转换为对象:

 # Split the series because the rnn cell needs time_steps features, each of shape:
 hidden = tf.split(0, config.n_steps, feature_mat)
 print (len(hidden), str(hidden[0].get_shape()))
 # New shape: a list of lenght "time_step" containing tensors of shape [batch_size, n_hidden]

控制台上显示的错误

Utils.getCardsInSets((ERR, DATA) => {
    if (!ERR) {
        allCards = DATA;
        console.log("Card data loaded. [" + Object.keys(DATA).length + "]");
    } else {
        console.log("An error occurred while getting cards: " + ERR);
    }
});

1 个答案:

答案 0 :(得分:0)

Utils.getCardsInSets返回undefinednull DATA。在上面的代码中,您没有将任何查询参数传递给方法,检查是否需要传递任何参数。

如果正在做的事情是正确的,那么方法将根据特定条件返回undefined/null。只需检查DATA,然后查看其密钥长度。

Utils.getCardsInSets((ERR, DATA) => {
    if (!ERR) {
        allCards = DATA;
        var datalength = (!!DATA) ? Object.keys(DATA).length : 0;
        console.log("Card data loaded. [" + datalength  + "]");
    } else {
        console.log("An error occurred while getting cards: " + ERR);
    }
});