0

我想在 js/jquery 中执行此操作:

var events = new Array();
var $event1 = [id, name, starttime, startposition];
var $event2 = [id2, name2, starttime2, startposition2];
var $event3 = [id3, name3, starttime3, startposition3];
events["fistcolumn"].push($event1, $event2, $event3);

这不起作用......你能告诉我怎么做吗?

4

5 回答 5

1
var events = {}, //lets try that with an object?
    event1 = [id, name, starttime, startposition],
    event2 = [id2, name2, starttime2, startposition2],
    event3 = [id3, name3, starttime3, startposition3];

//lets join the arrays and stick them in the object
events["fistcolumn"] = event1.concat(event2).concat(event3);  

//now events.fistcolumn (kinky name) contains all the values from the arrays

if (events.fistcolumn[5] == name2) //true
于 2012-08-20T10:02:11.153 回答
0

javascript中没有关联数组,你可以使用一个对象:

var events = {};
events["firstcolumn"] = event1;

另外,丢失变量前面的 $,即 php 语法 :)

更新:

对于您的事件,您可能还应该使用对象:

var event2 = { id: id2, name: name2, starttime: starttime2, ... };

于 2012-08-20T09:58:48.147 回答
0

这可能有效。因为如果你想像下面那样做,

 events["fistcolumn"] = events1;

事件必须是一个对象。

events.push($event1);
events.push($event2);
events.push($event3);
于 2012-08-20T10:00:00.670 回答
0
var events = new Array(); 
var $event1 = ['id', 'name', 'starttime', 'startposition']; 
var $event2 = ['id2', 'name2', 'starttime2', 'startposition2']; 
var $event3 = ['id3', 'name3', 'starttime3', 'startposition3']; 
events["fistcolumn"] = $event1.concat($event2).concat($event3);

我将这些变量更改为字符串仅用于测试目的,您可以将其更改回来。

于 2012-08-20T10:04:42.613 回答
0
var events = {};  // events object

var $event1 = [id, name, starttime, startposition];
var $event2 = [id2, name2, starttime2, startposition2];
var $event3 = [id3, name3, starttime3, startposition3];

那么你可以这样做

events["fistcolumn"] = [$event1, $event2, $event3];

或者像这样

events["fistcolumn"] = [];
events["fistcolumn"].push($event1);
events["fistcolumn"].push($event2);
events["fistcolumn"].push($event3);
于 2012-08-20T10:40:24.330 回答