我使用的是javascript和node.js。我的代码中有以下几行:
var countryName = "Turkey";
var jsonPath = '../'+countryName+'/PersonalDetails.json';
console.log(jsonPath);
var PersonalDetails = require(jsonPath);
这给出了错误:无法找到模块' ../ Turkey / PersonalDetails.json'
但是当我使用
时var PersonalDetails = require('../Turkey/PersonalDetails.json');
它工作正常。我错过了什么?
还附上我的json文件以供参考。
{
"fields":[
{
"fieldType":"Radio",
"fieldLabel":"Relevance to the transaction :",
"disclosureField":"" ,
"fieldList":["One carrying out the transaction","One on behalf of him/her the transaction is carried out","Indirect Relevance"]
},
{
"fieldType":"Radio",
"fieldLabel":"Is ID Card False",
"disclosureField":"",
"fieldList":["Yes","No"]
},
{
"fieldType":"Radio",
"fieldLabel":"Sex :",
"disclosureField":"gender",
"fieldList":["Male","Female","Unknown"]
},
{
"fieldType":"TextInput",
"fieldLabel":"First Name",
"disclosureField":"identity.first_name",
"fieldList":[]
},
{
"fieldType":"TextInput",
"fieldLabel":"SurName",
"disclosureField":"identity.last_name",
"fieldList":[]
},
{
"fieldType":"NumberInput",
"fieldLabel":"TR ID Number :",
"disclosureField":"",
"fieldList":[]
},
{
"fieldType":"NumberInput",
"fieldLabel":"Tax Number :",
"disclosureField":"",
"fieldList":[]
},
{
"fieldType":"TextInput",
"fieldLabel":"Mother's Name :",
"disclosureField":"",
"fieldList":[]
},
{
"fieldType":"TextInput",
"fieldLabel":"Father's Name :",
"disclosureField":"",
"fieldList":[]
},
{
"fieldType":"TextInput",
"fieldLabel":"Nationality :",
"disclosureField":"nationality",
"fieldList":[]
},
{
"fieldType":"TextInput",
"fieldLabel":"Occupation :",
"disclosureField":"occupation",
"fieldList":[]
},
{
"fieldType":"TextInput",
"fieldLabel":"Additional Information :",
"disclosureField":"",
"fieldList":[]
}
]
}
答案 0 :(得分:0)
您可以定义一条路径:
var path = require(__dirname + "yourpath");
如果有帮助,请告诉我
编辑:
var jsonPath = require(__dirname + '/../' + countryName + '/PersonalDetails.json');