简体   繁体   English

存储和加载数据Javascript的最简单方法是什么?

[英]What's the easiest way to store and load data Javascript?

I have a Hashmap for storing Loudness values. 我有一个用于存储响度值的哈希图。 The code is in Javascript HTML5. 该代码在Javascript HTML5中。

var Loudness = {};
Loudness['f125'] = {right: [], left: []};
Loudness['f125']['right'].push([0,10,30, 40]);
Loudness['f125']['left'].push([5,15,35,45]);
Loudness['f250'] = {right: [], left:[] };
Loudness['f500'] = {right: [], left: []};
Loudness['f1000'] = {right: [], left: []};

I also have a Hashmap for storing Gain values (basically the same as up, also w/ "right" and "left" (right and left side of the audiospeakers) properties. 我还有一个用于存储增益值(基本上与up相同,还带有“ right”和“ left”(扬声器的左右两侧))的Hashmap。
The difference is the name of the HM and the values of the array. 区别在于HM的名称和数组的值。 I have a lot of frequencies (keys, for instance f250, f500, …) still to insert to each Hashmap. 我还有很多频率(键,例如f250,f500等)要插入到每个Hashmap中。 Is there a more efficient way to declare each frequency key and its properties? 有没有更有效的方法来声明每个频率键及其属性?
Does it make sense to use a Hashmap inside a Hashmap? 在Hashmap中使用Hashmap是否有意义?
Also, if the Gain HM is put inside the Loudness HM, how would the new Loudness HM disposition be like? 另外,如果将Gain HM放在Loudness HM内,新的Loudness HM的配置将如何? Do the keys(frequencies) remain the same? 按键(频率)保持不变吗? Is the GainHashmap now a new property? GainHashmap现在是新属性吗? I haven't found how to implement it. 我还没有找到如何实现它。 What would the syntax be like? 语法是什么样的?
What's the easiest way to insert and easily change data ("loudness" and "gain" for "right" and "left", for each frequency). 插入和轻松更改数据的最简单方法是什么(每个频率的“右”和“左”的“响度”和“增益”)。
Is there a better option in your opinion? 您认为有更好的选择吗? WebStorageAPI, Hashmap inside Hashmap? WebStorageAPI,Hashmap中的Hashmap?
Please consider that I'm not such an expert in programming. 请考虑我不是编程专家。 Any help is greatly Appreciated. 任何帮助是极大的赞赏。

var Loudness = {};
    var freqs = ['f125', 'f250', 'f500', 'f1000', 'f1250'];
    var values = [0, 10, 30, 40, 5, 15, 35, 45];
    for(var i in freqs){
        Loudness[freqs[i]] = {left : [], right : []};
        Loudness[freqs[i]].Gain = {left : [], right : []};
        for(var j in values){
            var v = values[j];
            if(v === 0 || v % 2 === 0){
                Loudness[freqs[i]]['right'].push(v);
                Loudness[freqs[i]].Gain['right'].push(v); 
            } else {
                Loudness[freqs[i]]['left'].push(v);
                Loudness[freqs[i]].Gain['left'].push(v); 
        }
    }
}

Try this one. 试试这个。 In order to access your gains: 为了获得您的收益:

Loudness['f125'].Gain.left[0]

Basically if you need more frequencies, just add them to freqs arrays. 基本上,如果您需要更多的频率,只需将它们添加到频率阵列。

So, the idea of Gain as property inside the Loudness HM is perfect. 因此,将增益作为Loudness HM内部属性的想法是完美的。
The problem is that this Loudness HM is not allowed to be accessed (wherever and however it was declared). 问题是不允许访问此Loudness HM(无论在何处被声明)。
1) I tried to make it acessible even through privileged methods returning it. 1)我试图通过特权方法返回它来使它成为可能。
2) I even declared it inside a constructor (using this.Loudness = {}; instead of var Loudness = {};, but am receiving errors like "Uncaught TypeError: Cannot read property '250' of undefined", when trying to access this value. Piece of the public method which uses it: 2)我什至在构造函数中声明了它(使用this.Loudness = {};而不是var Loudness = {} ;,但是在尝试访问时收到诸如“ Uncaught TypeError:Can not read property'250'of undefined”之类的错误这个值,使用它的一部分公共方法:

AudiometrySample.prototype.loudnessToGain = function (frequency, loudness, activeChannel) {
...
console.log("this.Loudness[250] is"+ this.Loudness);
if (this.activeChannel === "right") {
  for (var j = 0; j < this.Loudness[this.frequency].right.length; j++) {
    if (this.Loudness[this.frequency].right[j] === this.loudness) {
      this.wantedGain = this.Loudness[this.frequency].Gain.right[j];
      this.currentPairIndex = j;
    }
  }
}

This console log gives "undefined" back. 此控制台日志返回“未定义”。 How to make it accessible? 如何使其可访问?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过内容,CSS,Javascript或其他方法格式化基于Web的数据的最简单方法是什么? - What's the easiest way to format web-based data by content, CSS, Javascript, or other method? 加载数据时暂停setInterval的最简单/最有效的方法是什么? JavaScript / jQuery - What's the easiest / most efficient way to pause setInterval while data is loading? JavaScript/Jquery 将外部数据加载到chrome扩展的最简单方法是什么 - What is the easiest way to load external data to chrome extension 在 JavaScript 中将数字转换为百分比的最简单方法是什么? - What's the easiest way to convert a number to a percentage in JavaScript? 在 Windows 上运行 .js javascript 文件的最简单方法是什么? - What's the easiest way to run a .js javascript file on windows? 将javascript动画置于背景的最简单方法是什么? - What's the easiest way to put the javascript animation to the background? 将文件链接到 Javascript 程序的最简单方法是什么? - What's the easiest way to link a file to a Javascript program? 在javascript中传递数据的最简单方法 - easiest way to pass the data in javascript 部署Meteor应用最简单的方法是什么? - What's the easiest way to deploy Meteor app? 更改数组值的最简单方法是什么 javascript - What is the easiest way of changing the values of an array javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM