我想更改输入到'en‘值中的inputLanguage。当我尝试这个方法时,没有定义它们返回的错误是英语。
这是我的alchemy.js
module.exports = function(Alchemy) {
Alchemy.language = function(inText, inputLanguage, outputLanguage, cb) {
console.log('Input text is ' + inText);
console.log('Input language is ' + inputLanguage);
console.log('Output language is ' + outputLanguage);
getCode(inputLanguage, outputLanguage, cb);
}
Alchemy.remoteMethod(
'language', {
http: {
path: '/language',
verb: 'get'
},
accepts: [{
arg: 'inText',
type: 'string',
required: true
}, {
arg: 'inputLanguage',
type: 'string',
required: true
}, {
arg: 'outputLanguage',
type: 'string',
required: true
}],
returns: {
arg: 'results',
type: 'string'
}
}
);
function getCode(inputLanguage, outputLanguage, cb) {
if (inputLanguage = english) {
inLang = en;
console.log('Input language is ' + inlang)
}
}
};发布于 2016-04-12 08:46:03
if (inputLanguage = english)块中存在问题
首先,english是未定义的变量,所以请定义它,或者如果要将其更改为string,则添加引号。
第二个问题是=符号,单个=是辅助,如果要比较变量,则需要使用==或===。
发布于 2016-04-12 08:47:14
您正在混淆if、变量和字符串的工作方式。没有一个名为english的变量,也没有en --而=赋值、==或===都在检查等式=> see here。
下面试一试:
if (inputLanguage === 'english') {
inLang = 'en';
console.log('Input language is ' + inlang)
}在JS中,字符串由"或'包围。
https://stackoverflow.com/questions/36567865
复制相似问题