私はの関連配列を持っています:
instrumentLookup: {
hh: {label: 'Hi Hat', type: 'hh'},
kd: {label: 'Kick Drum', type: 'kd'},
o1: {label: 'other1', type: 'o1'},
o2: {label: 'other2', type: 'o2'}
}
この構造でいいと思いますが、もっといい方法があるかもしれません。
この関数でこのリストから楽器を作成しようとしています。ここで、パラメーターはaddedInstrument
ラベルと同じ文字列として入力されるためhh
、、、、....:kd
o1
addInstrument: function(addedIntrument) {
console.warn(addedIntrument);
var newLabel = this.defaults.instrumentLookup.addedIntrument.label;
var newType = addedIntrument;
console.warn(newLabel + ' ' + newType)
// push it to the list
// this.unusedInstruments.push({label:newLabel, type:newType});
}
これにはいくつかの質問があります。お気軽に一部またはすべてに回答するか、代替案を提案してください。
- オブジェクトが連想配列の値である場合、オブジェクトのプロパティにどのようにアクセスしますか?
- Associate 配列から入れ子になった object{type: {other attrs}} の array[] に変更する必要がありますか?