[英]Javascript ERROR, undefined, not an object
I am new in JavaScript, And I am trying to map my controller's buttons and leds for mixxx application. 我是JavaScript的新手,并且我试图映射控制器按钮和mixxx应用程序的led。 Is that an object, an array?
那是一个对象,一个数组吗? var is missing.
var丢失。
BehringerCMDMM1.leds = [
// Master
{ "shiftButton" : 0x12 },
// Deck 1
{ "sync" : 0x30 },
// Deck 2
{ "sync" : 0x33 }
];
I have an error here, 我这里有一个错误,
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);
} }
about "shiftButton" as undefined. 关于“ shiftButton”未定义。
also I have this function 我也有这个功能
BehringerCMDMM1.setLED = function(value, status) {
status = status ? 0x7F : 0x00;
midi.sendShortMsg(0x94, value, status);
} }
This is from a javascript file I found on the internet created for a different controller. 这是从我在互联网上为其他控制器创建的javascript文件中获得的。 So, I am trying things to understand how can I configure mine.
因此,我正在尝试了解如何配置我的。
BehringerCMDMM1.leds
is an array of objects. BehringerCMDMM1.leds
是一个对象数组。 Within that array, the element at index 0 is an object that has a shiftButton
property. 在该数组中,索引为0的元素是一个具有
shiftButton
属性的对象。 Thus, the only way to get the 0x12
value in your example is to do this: 因此,在您的示例中获取
0x12
值的唯一方法是执行以下操作:
BehringerCMDMM1.leds[0]['shiftButton']
So when this code executes... 所以当这段代码执行时...
var deck = BehringerCMDMM1.groupToDeck(group);
...the value of deck
is probably something other than 0, and you're accessing one of the sync
objects in the BehringerCMDMM1.leds
array. ...
deck
的值可能不是0,您正在访问BehringerCMDMM1.leds
数组中的sync
对象之一。 For example, if the value of deck
was 1, then this... 例如,如果
deck
的值为1,则此...
BehringerCMDMM1.leds[deck]['shiftButton']
...will be undefined
because you're effectively doing this: ...将是
undefined
因为您正在有效地执行此操作:
BehringerCMDMM1.leds[1]['shiftButton']
Ok, 好,
I am new in JavaScript, And I am trying to map my controller's buttons and leds for mixxx application.
我是JavaScript的新手,并且我试图映射控制器按钮和mixxx应用程序的led。 Is that an object, an array?
那是一个对象,一个数组吗?
You have a array of objects. 您有一组对象。
var is missing.
var丢失。
You should test what is inside yout deck variable. 您应该测试一下您的牌组变量中的内容。 Try this:
尝试这个:
console.log(deck);
if (deck in BehringerCMDMM1.leds) {
BehringerCMDMM1.setLED(BehringerCMDMM1.leds[deck]["shiftButton"], BehringerCMDMM1.shift);
} else {
console.log("Index: "+deck+" doesn't exist");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.