2016-04-07 59 views
0

這是我activeRadioListYii2在ArrayHelper concate自動遞增字母::地圖()

<?= Html::activeRadioList($model, 'qa_value', ot\QuestionAnswer::getAnswerOptions($model), [ 
      'encode' => false, 
      'separator' => '<br/>', 
      'itemOptions' => [ 
       'labelOptions' => ['class' => 'radio-inline'] 
      ],    
     ]); ?> 

這是我getAnswerOption()函數來獲得期權價值

public static function getAnswerOptions($qModel) 
{ 
    $answerData = $qModel->qaQuestionInstance->getTqiQuestionAns()->asArray()->all(); 
    return \yii\helpers\ArrayHelper::map($answerData, 'qna_id', function ($model) { 
     $l = 'a'; 
     return $l++.'. '.$model['qna_answer']; 
    });  
} 

這回這樣

enter image description here

但是我wa nt得到

a。假

b。真

+0

嘗試'$ L = 'A' 變化; return \ yii \ helpers \ ArrayHelper :: map($ answerData,'qna_id',function($ model)use($ l){ return $ l ++。'。'。$ model ['qna_answer']; } );'在你的'getAnswerOptions'函數 –

+0

這一個不工作... – vishuB

+0

你在這之後得到什麼? –

回答

0

是的,我讓我的輸出到getAnswerOptions()功能

public static function getAnswerOptions($qModel) 
{ 
    $answerData = $qModel->qaQuestionInstance->getTqiQuestionAns()->asArray()->all(); 
    $l = 'a'; 
    $i = 0; 
    foreach ($answerData as $ad) 
    { 
     $answerData[$i++]['qna_answer'] = ($l++.'. &nbsp;'.$ad['qna_answer']); 
    } 
    return \yii\helpers\ArrayHelper::map($answerData, 'qna_id', function ($model) { 
     return $model['qna_answer']; 
    });  
}