使用自定义计算机时出现运行时异常问题:
我创建了一个自定义机器,它接受三个参数:一个数组,一个id和一个创建crud机器。它旨在循环遍历数组并使用数组元素和id调用机器,我使用循环机作为灵感但我得到了错误500.
TypeError: Cannot read property 'models' of undefined
at Object.module.exports.fn (/Users/dev/Desktop/workspace/trifago/api/machines/_project_2294_0.0.5/create_ntag.js:37:14)
at _runMachine (/Users/dev/Desktop/workspace/trifago/node_modules/machine/lib/Machine.prototype.exec.js:336:17)
at afterCacheLookup (/Users/dev/Desktop/workspace/trifago/node_modules/machine/lib/Machine.prototype.exec.js:347:7)
at _cacheLookup (/Users/dev/Desktop/workspace/trifago/node_modules/machine/lib/Machine.prototype.exec.js:160:25)
at Machine_prototype_exec [as exec] (/Users/dev/Desktop/workspace/trifago/node_modules/machine/lib/Machine.prototype.exec.js:211:5)
at /Users/dev/Desktop/workspace/trifago/api/machines/_project_2294_0.0.5/bulkcreateNtags.js:57:29
at /Users/dev/Desktop/workspace/trifago/api/machines/_project_2294_0.0.5/node_modules/async/lib/async.js:125:13
at Array.forEach (native)
at _each (/Users/dev/Desktop/workspace/trifago/api/machines/_project_2294_0.0.5/node_modules/async/lib/async.js:46:24)
at async.each (/Users/dev/Desktop/workspace/trifago/api/machines/_project_2294_0.0.5/node_modules/async/lib/async.js:124:9)
at Object.module.exports.fn (/Users/dev/Desktop/workspace/trifago/api/machines/_project_2294_0.0.5/bulkcreateNtags.js:51:5)
at _runMachine (/Users/dev/Desktop/workspace/trifago/node_modules/machine/lib/Machine.prototype.exec.js:336:17)
at afterCacheLookup (/Users/dev/Desktop/workspace/trifago/node_modules/machine/lib/Machine.prototype.exec.js:347:7)
at _cacheLookup (/Users/dev/Desktop/workspace/trifago/node_modules/machine/lib/Machine.prototype.exec.js:160:25)
at Machine_prototype_exec [as exec] (/Users/dev/Desktop/workspace/trifago/node_modules/machine/lib/Machine.prototype.exec.js:211:5)
at Object.Machine.build.fn (/Users/dev/Desktop/workspace/trifago/api/controllers/TagswithquestionidController.js:30:20) [TypeError: Cannot read property 'models' of undefined]
这是我的机器:
module.exports = {
"inputs": {
"tags": {
"id": "ce459bad-8a34-4d31-88d1-356bce99a427",
"friendlyName": "tags",
"description": "tags to be inserted",
"typeclass": "array",
"required": true,
"addedManually": true
},
"questionid": {
"id": "460b6d0a-296c-467a-b9f4-31849c414be9",
"friendlyName": "question id",
"description": "",
"example": 1,
"required": true,
"addedManually": true
},
"worker": {
"id": "d0dce741-1a7b-43c5-b45d-3b7cf11d2bf3",
"friendlyName": "worker",
"description": "",
"typeclass": "machine",
"required": true,
"addedManually": true
}
},
"exits": {
"error": {
"example": undefined
},
"success": {
"void": true,
"friendlyName": "then",
"variableName": "result",
"description": "Normal outcome."
}
},
"defaultExit": "success",
"fn": function(inputs, exits, env) {
var async = require('async');
if (!inputs.worker.inputs || typeof inputs.worker.inputs != 'object') {
return exits.error("Worker misconfigured: no inputs object found");
}
var workerInputs = Object.keys(inputs.worker.inputs);
if (workerInputs.length === 0) {
return exits.error("Worker misconfigured: inputs object empty");
}
var loop = async.each;
loop(inputs.tags, function(item, cb) {
var config = {};
config[workerInputs[0]] = item;
config[workerInputs[1]] = inputs.questionid;
config[workerInputs[2]] = 17;
inputs.worker(config).exec(cb);
}, exits);
},
"identity": "bulkcreateNtags"
};
带错误的行是create_ntag.js:37代码:
env.sails.models.ntag.create(env.sails.util.objCompact(inputs)).exec(function(err, records) {
提前致谢