1

How can the equivalent in PHP be done in JS?:

$this->gridColumnData[] = array('field' => 'id', 'width' => 50, 'title' => 'Enquiry Id') ;
$this->gridColumnData[] = array('field' => 'Name', 'width' => 90, 'title' => 'Name') ;

I know how to create a simple array like:

var myArray = [[23, 45, 12], ['stringA', 'stringB']] ;

But is it possible to do something like:

var myArray = ["numbers" => ["A" => 23, "B" => 45, "C" => 12], "strings" => ["firstone" => 'stringA', "secondone" => 'stringB']];
4

2 回答 2

1

你所描述的是一个对象文字,一个异构键值对的容器。在这种情况下,我们必须将它与数组结合起来以获得您所描述的行为:

var myArray = {
    numbers: [{ A: 23, B: 45, C: 12 }],
    strings: { firstone: "stringA", secondone: "stringB" }
};

前任。要访问B对象中的属性,您必须执行myArray.numbers[0].B. 要获得 的值"secondone",请执行myArray.strings.secondone

于 2013-02-16T13:57:56.573 回答
1

它是 JS 中的一个对象:

var myObjArray = {
    numbers : { A : 23, B : 45, C : 12 }, 
    strings : {firstone : 'stringA', secondone : 'stringB'}
};

访问方式:

myObjArray['numbers']['A'];
于 2013-02-16T13:57:35.373 回答