restData = currentNode.Restdata;
chain = {
name: currentNode.name,
body: function (job, cb) {
var client = restify.createClient({
url : restData.URL
});
switch (restData.Type) {
case 'GET':
return client.get('/', function (err, req, res, obj) {
if (err) {
return cb(err.name + ': ' + err.body.message);
} else {
return cb(null, 'Data found');
}
});
break;
default:
break;
}
}
};
在上面的例子中,我无法将restData变量访问到body:function(){}。任何人都可以帮我解决这个问题,我可以访问bodyData到body函数。
让我举个例子:
这是我当前的json对象:
var inputJson = {
"nodes": [{
"name": "Fetch Ticket from google",
"id": 0,
"x": 0,
"y": 0,
"width": 350,
"nodetype": "restclient",
"Restdata": {
"Type": "GET",
"URL": "https://google.com",
"authorization": "OAuth2",
"authparams": {
"accessToken": "xxxxxxx"
},
"body": [{
"start": "&&last_run()",
"end": "&&now()"
}]
},
"outputConnectors": [{
"name": "A"
}]
}
]
};
现在,我想通过动态将此json对象转换为另一种json对象格式,如下所示:
{
name: "Sample Workflow",
chain: [
{
name: "A Task",
timeout: 30,
retry: 2,
body: function (job, cb) {
var client = restify.createClient({
url : "https://google.com"
});
return client.get('/', function (err, req, res, obj) {
if (err) {
return cb(err.name + ': ' + err.body.message);
} else {
return cb(null, 'Data found');
}
});
},
fallback: function (err, job, cb) {
job.the_err = err;
return cb(null);
}
}
],
timeout: 300,
onError: [{
name: "Try another solution",
body: function (job, cb) {
cb("bhai bhul chhe kaik");
}
}]
};
而且,我是这样做的:
var workflowChains = [];
var finalWorkflow = {
name: "Workflow 1",
chain: workflowChains,
timeout: 300,
onError: []
};
var inputNodes = inputJson.nodes;
var inputConnections = inputJson.connections;
for (var i = 0; i < inputNodes.length; i++) {
var currentNode = inputNodes[i];
var currentConnecter = inputConnections[i];
restData = currentNode.Restdata;
chain = {
name: currentNode.name,
body: function (job, cb) {
var client = restify.createClient({
url : restData.URL
});
switch (restData.Type) {
case 'GET':
return client.get('/', function (err, req, res, obj) {
if (err) {
return cb(err.name + ': ' + err.body.message);
} else {
return cb(null, 'Data found');
}
});
break;
default:
break;
}
}
};
workflowChains.push(chain);
}
并且,在这种情况下,我如何将https://google.com分配给
中的网址var client = restify.createClient({
url : restData.URL
});