2011-06-22 4 views
0

私は次のif文を採用コードの中に入れる必要がありますが、それが存在するなら有効ではありません。私は何か他の方法で同じことをすることができるいくつかの方法はありますか?Mootools 1.3どうすれば "注入"機能の中でif文を取得できますか?

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 Element('span.bold', {text:row.bold}), 
); 

ele.iject(... 

答えて

1

私はMooToolsのに非常に慣れていないんだけど、これは動作しないだろう、なぜ私は表示されません。

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

乾杯:Pがすべき'思考' – Nicekiwi

1

即時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}), 
); 
関連する問題