开发者

Mootools 1.3 How can I have get an if statement inside an "Inject" function?

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}),
);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜