0

大家早上好。这是我的问题:

我是 Node.js 的新手,我决定尝试 Geddy 框架,因为它看起来非常强大。所以,我正在关注本教程。当我向 ToDo 模型添加一些验证时,它会抛出一个错误并且我无法启动服务器。

欢迎任何帮助。

这里的代码:

var ToDo = function () {
    this.defineProperties({
        tittle: {type: 'string', required: true},
        status: {type: 'string', required:true},
    });

    this.validatesPresent('title');
    this.validatesLength('title', {min: 5});

    this.validatesWithFunction('status', function (status) {
        return status == 'open' || status == 'done';
    }, {message: "Status must be 'open' or 'done.'"});

};

ToDo = geddy.model.register('ToDo', ToDo);

这是控制台输出

C:\Users\rvela\Documents\NodejsProjects\to_do>geddy
[Thu, 28 Nov 2013 16:16:56 GMT] INFO Server starting with config: {
    "environment": "development",
    "workers": 1,
    "port": 4000,
    "spdy": null,
    "ssl": null,
    "detailedErrors": true,
    "flash": {
        "defaultClass": "alert",
        "inlineClasses": {
            "success": "alert alert-success",
            "alert": "alert",
            "error": "alert alert-error",
            "info": "alert alert-info"
        },
        "blockClasses": {
            "success": "alert alert-block alert-success",
            "alert": "alert alert-block",
            "error": "alert alert-block alert-error",
            "info": "alert alert-block alert-info"
        }
    },
    "debug": true,
    "rotateWorkers": false,
    "rotationWindow": 7200000,
    "rotationTimeout": 300000,
    "logDir": "C:\\Users\\rvela\\Documents\\NodejsProjects\\to_do\\log",
    "gracefulShutdownTimeout": 30000,
    "heartbeatInterval": 5000,
    "heartbeatWindow": 20000,
    "staticFilePath": "C:\\Users\\rvela\\Documents\\NodejsProjects\\to_do\\public",
    "cacheControl": {
        "expires": {
        "default": 0
        }
    },
    "sessions": {
        "store": "memory",
        "key": "sid",
        "expiry": 1209600
    },
    "cookieSessionKey": "sdata",
    "i18n": {
        "defaultLocale": "en-us",
        "loadPaths": [
            "C:\\Users\\rvela\\Documents\\NodejsProjects\\to_do\\config\\locales"
        ]
    },
    "hostname": null,
    "fullHostname": null,
    "connectCompatibility": false,
    "model": {
        "defaultAdapter": "filesystem"
    }
}
[Thu, 28 Nov 2013 16:16:56 GMT] INFO Creating 1 worker process.

C:\Users\rvela\AppData\Roaming\npm\node_modules\geddy\node_modules\model\lib\index.js:1182
    reg[this.name].properties[name].validations[condition] =
                                   ^
TypeError: Cannot read property 'validations' of undefined
    at validates (C:\Users\rvela\AppData\Roaming\npm\node_modules\geddy\node_modules\model\lib\index.js:1182:36)
    at null.validatesPresent (C:\Users\rvela\AppData\Roaming\npm\node_modules\geddy\node_modules\model\lib\index.js:1137:33)
    at ToDo (C:\Users\rvela\Documents\NodejsProjects\to_do\app\models\to_do.js:9:10)
    at Object.utils.mixin.registerDefinition (C:\Users\rvela\AppData\Roaming\npm\node_modules\geddy\node_modules\model\lib\index.js:835:15)
    at Object.utils.mixin.register (C:\Users\rvela\AppData\Roaming\npm\node_modules\geddy\node_modules\model\lib\index.js:822:17)
    at Object.<anonymous> (C:\Users\rvela\Documents\NodejsProjects\to_do\app\models\to_do.js:18:20)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
[Thu, 28 Nov 2013 16:16:57 GMT] ERROR Worker 8640 died.

作为最终信息。我使用的是 Windows 7。我有 node.js v0.10.22 和 Geddy v0.11.8

4

1 回答 1

0

你有一个双“t”。

this.defineProperties({
    tittle: {type: 'string', required: true}, //this should be title
    status: {type: 'string', required:true}, // and this comma should be deleted
});
于 2013-11-29T13:43:29.303 回答