dqjl0906 2014-05-21 00:47
浏览 54
已采纳

单击选项卡中的链接,但激活第二个选项卡上的链接

I created a web page with two tabs, each page having a list of links. When I click on a link on first tab, the link on the second tab is activated. That is unless its a row number that exceeds the number of rows on the second tab. The output HTML is correct. Both tabs by themselves work fine.

I am using Yii 1.1.14, php 5.4.11

Controller Action:

    public function actionTest5() {

    $fileNew = new File;

    $criteria = new CDbCriteria;
    $criteria->select='id,name,description';
    $criteria->condition='t.user_id='.(int)Yii::app()->user->id;;
    $criteria->order='t.date_updated desc, t.date_entered desc';
    $criteria->limit=5;
    $templateList=File::model()->findAll($criteria);

    $criteria = new CDbCriteria;
    $criteria->select='id,name,description';
    $criteria->condition='t.user_id='.(int)Yii::app()->user->id;;
    $criteria->order='t.date_updated desc, t.date_entered desc';
    $criteria->limit=3;
    $listFile=  Listfile::model()->findAll($criteria); 

    $docI = new Document;
    $fileNew = new File;
    $url = Yii::app()->createUrl('test/setup');                    

    if(isset($_POST['File']) OR isset($_POST['Document'])) 
        $this->redirect($url);

    $this->render('test5', array(
        'model'=>$docI,
        'templateList'=>$templateList,
        'listFile'=>$listFile,
        'fileNew'=>$fileNew,                          
    ));   
} 

View File test5:

<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'setup-form',
    'enableClientValidation'=>true,
));
$tabArray=array();
$tabArray["Tab1"] = array(
    'id'=>'1',
    'content'=>$this->renderPartial('_testTab1',
        array(
            'tabNum'=>1,
            'form'=>$form,
            'model'=>$model,
            'templateList'=>$templateList,
        ),TRUE));

$tabArray["Tab2"] = array(
    'id'=>'2',
    'content'=>$this->renderPartial('_testTab2',
        array(
            'tabNum'=>2,
            'form'=>$form,
            'model'=>$model,
            'listFile'=>$listFile,
        ),TRUE));

$this->widget('zii.widgets.jui.CJuiTabs',array(
    'tabs'=>$tabArray,
    'id'=>'MyTab-Menu',
));
?> 
<?php $this->endWidget(); ?>
</div>

This is the partial view _testTab1:

<table class="setup">
 <?php echo '<thead><th></th><th>File Name</th><th>Load File</th><th>Delete</th></thead>' ?>
    <?php foreach ($templateList as $i=>$file): ?>
            <tr id="trow">
                <td><?php echo CHtml::activeHiddenField($file, "[$i]id"); ?></td>
                <td><?php echo 'fileID: ['.$file['id'].']'; ?></td>
                <td><?php
                    echo CHtml::link('Reload File','#',
                            array('submit'=>array('setupFile','id'=>$i),
                                'id' => 'setup_' . $i . '_reload',
                                'value' => (int) $i,
                                'name' => 'setupFile',
                        ));
                ?></td>
                <td><?php
                    echo CHtml::link('Delete','#',
                            array('submit'=>array('fileDelete','id'=>$i),
                                'id' => 'setup_' . $i . '_delete',
                                'value' => (int) $i,
                                'name' => 'delete',
                                'confirm' => 'Are you sure you want to delete file '.$file['id'].'?',                                  
                        ));
                ?></td>                 
            </tr>
<?php endforeach; ?>
</table>

This is the partial view _testTab2:

<table class="setup">
 <?php echo '<thead><th></th><th>File Name</th><th>Load File</th><th>Delete</th></thead>' ?>
     <?php foreach ($listFile as $i => $file): ?>
            <tr id="trow">
                <td><?php echo CHtml::activeHiddenField($file, "[$i]id"); ?></td>
                <td><?php echo 'fileID: ['.$file['id'].']'; ?></td>
                <td><?php
                    echo CHtml::link('Reload File','#',
                            array('submit'=>array('setupFileList','id'=>$i),
                                'id' => 'setup_' . $i . '_reload',
                                'value' => (int) $i,
                                'name' => 'setupFileList',
                        ));
                ?></td>
                <td><?php
                    echo CHtml::link('Delete','#',
                            array('submit'=>array('fileListDelete','id'=>$i),
                                'id' => 'setup_' . $i . '_delete',
                                'value' => (int) $i,
                                'name' => 'delete',
                                'confirm' => 'Are you sure you want to delete file '.$file['id'].'?',                                
                        ));
                ?></td>                 
            </tr>
<?php endforeach; ?>
</table>

On post, the File[x]['id']'s are set with the x=row number and id being the hidden field (same applies to Listfile for second tab rows). When Reload is clicked, the following action is loaded. It gets the x value (row number) and from that determines the id value. Then it loads the test/uploadFile/id page. The problem is that when I click on the Reload (or delete) link for the first three rows on the first tab, I get the id for the second tab. When I do this for the last two rows on the first tab, I get the correct id value. All links on the second tab work as expected as do each of the tabs if they are loaded individually.

public function actionSetupFile($id) {
    $fileName='';
    if(isset($_POST['File'])) {
        if(isset($_POST['File'][(int)$id]['id'])) {
            $selected = $_POST['File'][(int)$id]['id'];
            $file=new File;
            $fileName=$file->getFileName($selected);
            $url = Yii::app()->createUrl('test/UploadFile/'.CHtml::encode((int)$selected));                    
        }     
    } else {
        $msg = 'Unable to complete request to upload file; try again ';  
        $url = Yii::app()->createUrl('test/setup');           
    }
    $this->redirect($url, array(
        'fileName'=>$fileName,
    ));
}

public function actionSetupFileList($id=null) {
    $fileName='';
    if(isset($_POST['Listfile'])) {
        if(isset($_POST['Listfile'][(int)$id]['id'])) {
            $selected = $_POST['Listfile'][(int)$id]['id'];
            $file=new Listfile;
            $fileName=$file->getFileListName($selected);
            $url = Yii::app()->createUrl('test/UploadFileList/'.CHtml::encode((int)$selected));                    
        }     
    } else {
        $msg = 'Unable to complete request to upload file; try again ';  
        $url = Yii::app()->createUrl('test/setup');           
    }
    $this->redirect($url, array(
        'fileName'=>$fileName,
    ));
}
  • 写回答

1条回答 默认 最新

  • dtamho6404 2014-05-23 19:53
    关注

    The post indices must be different for each tab. One way to do this is to use a multiplier for the second tab, defined as $k=100*($i+1); $i+1 because $i is 0 first and index for first row would be 0 for both tabs. Of course, some other multiplier could be used.

    <table class="setup">
     <?php echo '<thead><th></th><th>File Name</th><th>Load File</th><th>Delete</th></thead>' ?>
         <?php foreach ($listFile as $i => $file): $k=($i+1)*100; ?>
                <tr id="trow">
                    <td><?php echo CHtml::activeHiddenField($file, "[$k]id"); ?></td>
                    <td><?php echo 'fileID: ['.$file['id'].']'; ?></td>
                    <td><?php
                        echo CHtml::link('Reload File','#',
                                array('submit'=>array('setupFileList','id'=>$k),
                                    'id' => 'setup_' . $k . '_reload',
                                    'value' => (int) $k,
                                    'name' => 'setupFileList',
                            ));
                    ?></td>
                    <td><?php
                        echo CHtml::link('Delete','#',
                                array('submit'=>array('fileListDelete','id'=>$k),
                                    'id' => 'setup_' . $k . '_delete',
                                    'value' => (int) $k,
                                    'name' => 'delete',
                                    'confirm' => 'Are you sure you want to delete file '.$file['id'].'?',                                
                            ));
                    ?></td>                 
                </tr>
    <?php endforeach; ?>
    </table>
    

    Alternatively, pass offset from view file (test5) where offset for second and subsequent tabs is count of entries in ALL prior tabs (i.e. 2nd tab: $offset=count($templateList)). Then instead of $k above, use $i + $offset):

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!