featherjs回调未定义

时间:2014-11-12 02:53:46

标签: javascript node.js express feathersjs

我试图使用feathersjs,但我无法通过示例程序(feathers.js主站点上的待办事项列表)。传递给函数的唯一事情是接收到的数据。 <{1}}和param始终未定义。

callback

我做错了什么?我需要使用旧版本吗?我目前正在使用&#34;最新的&#34;我var myService = { find: function(params, callback) {}, get: function(id, params, callback) {}, create: function(data, params, callback) {}, update: function(id, data, params, callback) {}, patch: function(id, data, params, callback) {}, remove: function(id, params, callback) {}, setup: function(app, path) {} }

中的羽毛

编辑:

我完全从http://feathersjs.com/#documentation

复制粘贴示例代码

编辑:添加了源文件:

package.json

// app.js
var bodyParser = require("body-parser");
var compression = require("compression");
var express = require("express");
var feathers = require("feathers");
var http = require("http");
var io = require("socket.io");

var v1 = require("./lib/v1");
var config = require("./lib/config");

var app = feathers()
    .configure(feathers.socketio())
    .use(bodyParser.json())
    .use("/v1", v1)

var port = process.env.PORT || 3000;
app.listen(port);

编辑:添加错误

//lib/v1.js
var v1Service = {
    find: function(params, callback) {
        console.log("finding");
        callback(null, [{
            "uuid": "blahblahblah"
        }]);
    },
    get: function(id, params, callback) {
        console.log("geting");
        callback(null, {
            "uuid": "blahblahblah"
        });
    },
    create: function(data, params, callback) {
        console.log("creating, args:" + JSON.stringify(callback));
        callback(null, {
            "uuid": "blahblahblah"
        });
    },
    update: function(id, data, params, callback) {
        console.log("updating");
        callback(null, {
            "uuid": "blahblahblah"
        });
    },
    patch: function(id, data, params, callback) {
        console.log("patching");
        callback(null, {
            "uuid": "blahblahblah"
        });
    },
    remove: function(id, params, callback) {
        console.log("removeing");
        callback(null, {
            "uuid": "blahblahblah"
        });
    },
    setup: function(app, path) {
        console.log("setup");
    }
}

module.exports = v1Service;

1 个答案:

答案 0 :(得分:1)

问题出在我的客户端javascript中。我错误地使用“发射”:

var sock = io.connect();
sock.emit("v1::create", {"some":"data"})

以上javascript不正确。需要提供两个附加参数:

var sock = io.connect();
sock.emit("v1::create", {"some":"data"}, {}, function(){ console.debug("IN CALLBACK") })

我认为问题不是来自客户端代码,而是