데이터 배열에서 함수를 수행하는 모듈을 모욕했습니다. 함수를 실행할 때 내 서버에서 결과를 얻지 만 변수가 내 변수에 저장되지 않은 것처럼 보입니다. 결과는 정의되지 않습니다. 누군가 내 배열을 내 서버에서 볼 수있을 때 그 배열이 왜 정의되지 않았는 지 말해 줄 수 있습니까? 코드에 어떤 문제가 있는지 먼저변수가 변수에 정의되지 않은 배열 표시
var net = require('net');
var foo = require('./employeeModule');
var _ = require('underscore');
var colors = require('colors/safe');
var server = net.createServer(
function(socket){
console.log("Client connection...");
socket.on('end', function(){
console.log("Client disconnected...");
});
// process data from client
socket.on('data', function(data){
var command = data.toString();
var results={};
console.log("Received Command: " +command);
if (command == "lookupByLastName Smith")
{
function lastName(results)
{
var results = foo.lookupByLastName('Smith');
console.log('These are the results: '+ results)
}
lastName();
}
else if (command == "addEmployee William Smith")
{
function addEmp(results)
{
var results = foo.addEmployee('William', 'Smith');
console.log('These are the results: '+ results)
}
addEmp();
}
else if (command == "lookupById 4")
{
function lookId(results)
{
var results = foo.lookupById(4);
console.log('These are the results: '+ Name)
}
lookId();
}
else if (command == "bye")
client.end();
else console.log(colors.green("**"+command+" Command not recognized!**"));
});
});
//listent for client connections
server.listen(1000, function(){
console.log("Listening for client connections");
});
이 호출에서 어떤 유형의 값을 얻고 있습니까? foo.addEmployee ('William', 'Smith'); – abdulbarik
foo.lookupByLastName ('Smith') 호출에서부터. 배열에서 선택된 요소를 가져옵니다. 이건 [{id : 1, firstName : 'John', lastName : 'Doe'}]처럼 보입니다. foo.addEmployee ('William', 'Smith')는 가져온 모듈에서 가져온 데이터에 요소를 추가하기 만합니다. –