Here is my condition: I have already known that I need fifteen objects to store event data, so I just declared fifteen variables:
var e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, 15;
function Event(title, content, logo, logo_in_black) {
this.title = title;
this.content = content;
this.logo = logo;
this.logo_in_black = logo_in_black;
}
According to the user click, I dynamically assign data to the object according to the user click:
e1 = new Event('Nike', 'BUY ONE GET ONE FOR FREE', logo_url, logo_url2);
Then show the result on the view:
$('#e-1').css('background-image', "url('" + e1.logo + "')");
I need to do the same thing fifteen times to put every event information to individual block looks like this: <div id="e-1">! So I just tried the following method and I thought it must be the solution: I put fifteen objects in an array.
var e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15;
var events = [e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15];
Assign the data and show on the view:
e1 = new Event('Nike', 'BUY ONE GET ONE FOR FREE', logo_url, logo_url2);
e2 = ...
e3 = ...
for (var i = 0; i < 15; i ++) {
$('#e-' + (i + 1)).css('background-image', "url('" + events[i].logo + "')");
}
But the way I tried to access the attributes is wrong: events[i].logo
Can anyone please tell me why this can't work?
Thanks a lot!