-3

如何创建以下格式的数组:


  var options =
                 [
                    {
                        title: 'Laziness',
                        start: new Date(y, m, d, 12, 0),
                        allDay: false
                    },
                    {
                        title: 'Dizziness,Sleepiness',
                        start: new Date(y, m, d+1, 19, 0),
                        allDay: false
                    },
                    {
                        title: 'Click for Google',
                        start: new Date(y, m, 28),
                        url: 'http://google.com/'
                    }
                ];

我试过这样:


for(var i in data)
           {
             options = {
                    title:data[i].eventNames,
                   start:data[i].eventDates
               };
            }

但它没有以正确的格式显示,我该如何实现

4

2 回答 2

0

You can try Like This

Javascript

var arr = [];
var len = 5; //Replace Ur data With Len, Take Data Length or count for loop
for (var i = 0; i < len; i++) {    
    arr.push({
        key: 1 + i,
        value : 1 + i + "Hi"
    });
}

Demo

于 2014-06-02T13:21:08.377 回答
-1

您可以在循环之前创建选项,然后在循环中推送对象:

options = [];
for(var i in data)
           {
             options.push( {
                    title:data[i].eventNames,
                   start:data[i].eventDates
               })
            }
于 2014-06-02T11:59:18.477 回答