无法使用多个ajaxLink来加载CJuiDialog小部件

发布于 2025-01-06 00:11:53 字数 4350 浏览 0 评论 0原文

我在 yii 中使用多个 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 显示为创建新方案,但单击链接时,它会显示旧的创建大学对话框而不是创建方案。

I have a problem when using multiple ajaxLink for loading CJuiDialog widget in yii. I'm using multiple dropdowns, each dropdown's value determine next dropdown.

Here is my code for viewing first dropdown and a link to create new item using Cdialog widget.

    <?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'); ?>">

this works pretty good.

here is the javascript code for loading next dropdown in the same view file

<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";

});
 });
}

The scheme drop down is loaded as the scheme view code is

 <?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'); ?> ">

the second ajaxLink is shown as create new scheme but on clicking the link it shows the old create university dialog box instead of create scheme.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小霸王臭丫头 2025-01-13 00:11:53

最简单的解决方案是随机创建导致问题的元素的 ID。
尝试

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

在 ajaxLink 的 $htmlOptions 数组中添加:

The simplest solution for this is to create the ID of the element that is causing problems as random.
Try adding:

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

in the $htmlOptions array of ajaxLink

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文