0
我不確定這是否可能,或者如果我採取了錯誤的方法,我嘗試過搜索,但我不確定這些條款。變量字典內容
我想一個變量傳遞到控制器字典,因此而不是使用「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'
}
...
}
究竟是什麼問題? – epascarello 2013-02-08 17:16:38
我不希望爲每個關鍵詞都寫一本字典,I.E.控制器將擁有所有的密鑰(由密鑰引用),我會爲每個密鑰複製主機名,端口,方法(很多額外的代碼可能有更短的版本,IE也更容易閱讀) – onaclov2000 2013-02-08 17:25:02
因此,製作一個方法'getOption(「PLAY」)'並返回帶有新插入路徑的對象。 – epascarello 2013-02-08 17:29:21