2012-02-15 31 views
1

我在yii中使用多個ajaxLink加載CJuiDialog小部件時出現問題。我使用多個下拉菜單,每個下拉菜單的值決定下一個下拉菜單。無法使用多個ajaxLink加載CJuiDialog小部件

這裏是我的代碼,用於查看第一個下拉框和使用Cdialog小部件創建新項目的鏈接。

<?php $cs = Yii::app()->getClientScript(); 
    $cs->registerCoreScript("jquery"); 
    ?> 
    <div class="form"> 
    <?php $form=$this->beginWidget('CActiveForm', array(
    'enableAjaxValidation'=>false, 
    )); ?> 
    <div class="row"> 
      <?php 
      echo $form->labelEx($model,'uname'); ?> 
      <?php echo $form->dropDownList($model,'uname',$model-   >getUniversityList(),array('onchange'=>'getSchemes(this.value)','empty'=>'Select university')); ?> 
      <?php echo $form->error($model,'uname'); ?> 
      <?php //create university dialoge box 
        if(!Yii::app()->user->isGuest) 
        { 
         echo CHtml::ajaxLink('create new university',array('university/dialoge'),array(
       'success'=>'js:function(data){ 
      $("#createUniversity").dialog("open"); 
       document.getElementById("create_university").innerHTML=data; 
           }')); 
      $this->beginWidget('zii.widgets.jui.CJuiDialog',array(
       'id'=>'createUniversity', 
       'options'=>array(
       'title'=>'Create University', 
       'autoOpen'=>false, 
       'modal'=>'true', 
       'width'=>'auto', 
       'height'=>'auto', 
      ), 
      )); 
      echo "<div id='create_university'></div>"; 
          $this->endWidget('zii.widgets.jui.CJuiDialog'); 
      } 
?> 
     <div id="scheme"> 
     </div> 
     </div> 
<?php $this->endWidget(); ?> 
</div> 
<input type="hidden" id="url" value="<?php echo $this->createUrl('scheme/test'); ?>"> 

這個工程很不錯。

這裏是在同一視圖文件加載下一個下拉的JavaScript代碼

<script type="text/javascript"> 
    function getSchemes(uid) 
    { 
    if(uid==""){ 
document.getElementById("scheme").innerHTML=''; 
    return; 
    } 
    jQuery(function($){ 

var url=document.getElementById("url").value; 
$.post(url, { uid:uid }, 
function(data){ 
document.getElementById("scheme").innerHTML=data; 
    document.getElementById("scheme_link").style.display="block"; 

}); 
}); 
} 

下拉加載作爲方案視圖代碼的方案是

<?php $cs = Yii::app()->getClientScript(); 
    $cs->registerCoreScript("jquery"); 
    ?> 
    <?php 
    echo "<div class=".'label'."><label for=".'sch'.">Scheme</label></div>"; 
    echo "<select id=".'sch'." onchange='getDepartments(this.value);'>"; 
    echo "<option value=".''.">"."Select Scheme</option>"; 
      foreach($schemes as $s) 
      { 
      echo "<option value='".$s->schemeid."' >".$s->scheme_name."</option>"; 
      } 
      echo "</select>"; 
     ?> 
    <?php 
     if(!Yii::app()->user->isGuest) 
     { 
         echo CHtml::ajaxLink('create new    Scheme',array('scheme/dialoge','id'=>5),array(
       'success'=>'js:function(data1){ 
      $("#createScheme").dialog("open"); 
       document.getElementById("create_scheme").innerHTML=data; 
           }'));?> 
           <?php 
           $this->beginWidget('zii.widgets.jui.CJuiDialog',array(
       'id'=>'createScheme', 
       'options'=>array(
       'title'=>'Create Scheme', 
       'autoOpen'=>false, 
       'modal'=>'true', 
       'width'=>'auto', 
       'height'=>'auto', 
      ), 
      )); 
      echo "<div id='create_scheme'></div>"; 
          $this->endWidget('zii.widgets.jui.CJuiDialog'); 
      } 
    ?> 
    <div id="department"> 
    </div> 
    <input type="hidden" id="urldepart" value="<?php echo $this->createUrl('department/test'); ?> "> 

第二ajaxLink被示出爲創建新的方案,但點擊鏈接時,它會顯示舊的創建大學對話框,而不是創建方案。

回答

0

最簡單的解決方法是創建引起問題的隨機元素的ID。 嘗試添加:

'id' => 'some-element'.uniqid() // avoid mutliple ajax request because of using live 
ajaxLink

的$ htmlOptions數組中