0

我正在尝试使用 feathersjs,但我无法通过示例程序(feathers.js 主站点上的待办事项列表)。唯一传递给函数的是接收到的数据。param并且callback总是未定义的。

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) {}
}

我做错了什么?我需要使用旧版本吗?我目前在我的羽毛中使用“最新”package.json

编辑:

我从字面上复制粘贴了来自http://feathersjs.com/#documentation的示例代码

编辑:源文件添加:

// 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;

编辑:添加错误

TypeError: undefined is not a function
    at Object.v1Service.get [as _super] (/api_dev/lib/v1.js:11:3)
    at Object.<anonymous> (/api/node_modules/feathers/lib/mixins/promise.js:6:30)
    at Object.self.(anonymous function) [as get] (/api/node_modules/feathers/node_modules/uberproto/lib/proto.js:61:21)
    at Socket.<anonymous> (/api/node_modules/feathers/lib/providers/socket/commons.js:27:23)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Socket.onevent (/api/node_modules/socket.io/lib/socket.js:327:8)
    at Socket.onpacket (/api/node_modules/socket.io/lib/socket.js:287:12)
    at Client.ondecoded (/api/node_modules/socket.io/lib/client.js:185:14)
    at Decoder.Emitter.emit (/api/node_modules/socket.io/node_modules/socket.io-parser/node_modules/component-emitter/index.js:134:20)
    at Decoder.add (/api/node_modules/socket.io/node_modules/socket.io-parser/index.js:247:12)
4

1 回答 1

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") })

我不认为问题出在客户端代码上,但它是

于 2014-11-12T13:39:30.500 回答