【问题标题】:What is a [[ param1, param2 ... ]] structure in javascript?javascript 中的 [[ param1, param2 ... ]] 结构是什么?
【发布时间】:2015-01-13 20:06:14
【问题描述】:

我正在使用 handsontable,但对 JavaScript 并不了解。我有:

$container.handsontable({
              startRows: 8,
              startCols: 6,
              rowHeaders: true,
              colHeaders: true,
              minSpareRows: 1,
              contextMenu: true,
              afterChange: function (change, source) {
                if (source === 'loadData') {
                  console.log(change);
                }

当我查看控制台时,我看到:

  [[4, "notes", "PLEASE SET", ""]]

这看起来不像一个标准的对象。它是什么以及如何访问它的参数?

【问题讨论】:

  • 我猜这是作为参数发送给 afterChange 函数的数组数组..!
  • 它的多维数组包含第一级的更改列表,第二级它为您提供rowpropoldValnewVal - 阅读documentation
  • 谢谢,非常感谢

标签: javascript jquery multidimensional-array handsontable


【解决方案1】:

这是一个array,其中第一个元素是一个包含 4 个元素的数组。

在您的浏览器 JavaScript 控制台(按 F12,然后转到控制台)或 jsconsole.com 中尝试此操作:

var arr =  [[4, "notes", "PLEASE SET", ""]]; // Initialize the array

console.log (arr[0]);    // [4, "notes", "PLEASE SET", ""]
console.log (arr[0][0]); // 4
console.log (arr[0][1]); // "notes"
console.log (arr[0][2]); // "PLEASE SET"
console.log (arr[0][3]); // ""
console.log (arr[0][4]); // undefined
console.log (arr[1]);    // undefined
console.log (arr[1][0]); // undefined

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-21
    • 2015-01-03
    • 2010-10-26
    • 1970-01-01
    • 2021-06-16
    相关资源
    最近更新 更多