我不确定这是否可能,或者我是否采取了错误的方法,我已经尝试过搜索,但我不确定这些条款。
我想将一个变量传递给控制器字典,所以在查找中我可以做一些类似控制器('OPTION','PLAY')的事情,而不是使用'PLAY'
var ip = '192.168.1.5'
var Keys = {
HOME: '/keypress/Home',
REV: '/keypress/Rev',
FWD: '/keypress/Fwd',
PLAY: '/keypress/Play',
SELECT: '/keypress/Select',
LEFT: '/keypress/Left',
RIGHT: '/keypress/Right',
DOWN: '/keypress/Down',
UP: '/keypress/Up',
BACK: '/keypress/Back',
INSTANTREPLAY: '/keypress/InstantReplay',
INFO: '/keypress/Info',
BACKSPACE: '/keypress/Backspace',
SEARCH: '/keypress/Search',
ENTER: '/keypress/Enter',
A: '/keypress/Lit_a'
}
由此:
var controller = {
PLAY:{
hostname: ip,
port: 8060,
path: Keys['PLAY'],
method: 'POST'
}
}
对此:
var controller = {
OPTION:{
hostname: ip,
port: 8060,
path: Keys[Key],
method: 'POST'
}
}
我试图避免以下情况
var controller = {
PLAY:{
hostname: ip,
port: 8060,
path: Keys['PLAY'],
method: 'POST'
}
FWD :{
hostname: ip,
port: 8060,
path: Keys['FWD'],
method: 'POST'
}
REV :{
hostname: ip,
port: 8060,
path: Keys['REV'],
method: 'POST'
}
...
}