I need the following if statement inside the adopt code, but its not valid if it is there. is there some way I can do the same some other way?
var ele = new Element('li').adopt(
new Element('span.title', {text:row.title}),
new Element('span.subtitle').adopt(
// Need this to work, but its invalid where it is atm
if(row.subtitle = 1)
{
new Element('img', {src:'images/subTitle.png'})
}
),
new Ele开发者_开发问答ment('span.bold', {text:row.bold}),
);
ele.iject(...
I'm not very familiar with MooTools, but I don't see why this wouldn't work:
var subtitle = new Element('span.subtitle');
if (row.subtitle == 1) subtitle.adopt(new Element('img', {src:'images/subTitle.png'}));
var ele = new Element('li').adopt(
new Element('span.title', {text:row.title}),
subtitle,
new Element('span.bold', {text:row.bold}),
);
Immediate if FTW:
var ele = new Element('li').adopt(
new Element('span.title', {text:row.title}),
new Element('span.subtitle').adopt(
(row.subtitle == 1) ? new Element('img', {src:'images/subTitle.png'}) : null
),
new Element('span.bold', {text:row.bold}),
);
精彩评论