Javascript 错误,未定义,不是对象
Javascript ERROR, undefined, not an object
我是 JavaScript 的新手,我正在尝试为 mixxx 应用程序映射我的控制器按钮和 LED。那是一个对象,一个数组吗?缺少 var。
BehringerCMDMM1.leds = [
// Master
{ "shiftButton" : 0x12 },
// Deck 1
{ "sync" : 0x30 },
// Deck 2
{ "sync" : 0x33 }
];
这里有错误,
BehringerCMDMM1.shiftButton = function (channel, control, value, status, group) {
// Note that there is no 'if (value)' here so this executes both when the shift button is pressed and when it is released.
// Therefore, BehringerCMDMM1.shift will only be true while the shift button is held down
var deck = BehringerCMDMM1.groupToDeck(group);
BehringerCMDMM1.shift = !BehringerCMDMM1.shift // '!' inverts the value of a boolean (true/false) variable
BehringerCMDMM1.setLED(BehringerCMDMM1.leds[deck]["shiftButton"], BehringerCMDMM1.shift);
}
关于 "shiftButton" 未定义。
我也有这个功能
BehringerCMDMM1.setLED = function(value, status) {
status = status ? 0x7F : 0x00;
midi.sendShortMsg(0x94, value, status);
}
这是我在互联网上找到的为不同控制器创建的 javascript 文件。所以,我正在尝试了解如何配置我的。
BehringerCMDMM1.leds
是一个对象数组。在该数组中,索引 0 处的元素是一个具有 shiftButton
属性 的对象。因此,在您的示例中获得 0x12
值的唯一方法是这样做:
BehringerCMDMM1.leds[0]['shiftButton']
所以当这段代码执行时...
var deck = BehringerCMDMM1.groupToDeck(group);
...deck
的值可能不是 0,并且您正在访问 BehringerCMDMM1.leds
数组中的 sync
对象之一。例如,如果 deck
的值为 1,则此...
BehringerCMDMM1.leds[deck]['shiftButton']
...将是 undefined
,因为您正在有效地执行此操作:
BehringerCMDMM1.leds[1]['shiftButton']
好的,
I am new in JavaScript, And I am trying to map my controller's buttons and leds for mixxx application. Is that an object, an array?
您有一个对象数组。
var is missing.
你应该测试你的 deck 变量里面有什么。试试这个:
console.log(deck);
if (deck in BehringerCMDMM1.leds) {
BehringerCMDMM1.setLED(BehringerCMDMM1.leds[deck]["shiftButton"], BehringerCMDMM1.shift);
} else {
console.log("Index: "+deck+" doesn't exist");
}
我是 JavaScript 的新手,我正在尝试为 mixxx 应用程序映射我的控制器按钮和 LED。那是一个对象,一个数组吗?缺少 var。
BehringerCMDMM1.leds = [
// Master
{ "shiftButton" : 0x12 },
// Deck 1
{ "sync" : 0x30 },
// Deck 2
{ "sync" : 0x33 }
];
这里有错误,
BehringerCMDMM1.shiftButton = function (channel, control, value, status, group) {
// Note that there is no 'if (value)' here so this executes both when the shift button is pressed and when it is released.
// Therefore, BehringerCMDMM1.shift will only be true while the shift button is held down
var deck = BehringerCMDMM1.groupToDeck(group);
BehringerCMDMM1.shift = !BehringerCMDMM1.shift // '!' inverts the value of a boolean (true/false) variable
BehringerCMDMM1.setLED(BehringerCMDMM1.leds[deck]["shiftButton"], BehringerCMDMM1.shift);
}
关于 "shiftButton" 未定义。
我也有这个功能
BehringerCMDMM1.setLED = function(value, status) {
status = status ? 0x7F : 0x00;
midi.sendShortMsg(0x94, value, status);
}
这是我在互联网上找到的为不同控制器创建的 javascript 文件。所以,我正在尝试了解如何配置我的。
BehringerCMDMM1.leds
是一个对象数组。在该数组中,索引 0 处的元素是一个具有 shiftButton
属性 的对象。因此,在您的示例中获得 0x12
值的唯一方法是这样做:
BehringerCMDMM1.leds[0]['shiftButton']
所以当这段代码执行时...
var deck = BehringerCMDMM1.groupToDeck(group);
...deck
的值可能不是 0,并且您正在访问 BehringerCMDMM1.leds
数组中的 sync
对象之一。例如,如果 deck
的值为 1,则此...
BehringerCMDMM1.leds[deck]['shiftButton']
...将是 undefined
,因为您正在有效地执行此操作:
BehringerCMDMM1.leds[1]['shiftButton']
好的,
I am new in JavaScript, And I am trying to map my controller's buttons and leds for mixxx application. Is that an object, an array?
您有一个对象数组。
var is missing.
你应该测试你的 deck 变量里面有什么。试试这个:
console.log(deck);
if (deck in BehringerCMDMM1.leds) {
BehringerCMDMM1.setLED(BehringerCMDMM1.leds[deck]["shiftButton"], BehringerCMDMM1.shift);
} else {
console.log("Index: "+deck+" doesn't exist");
}