attajob 2012-01-03 21:55:21 4939次浏览 13条回复 0 0 0
<div class="row">
    <?php echo $form->labelEx($model,'province'); ?>
    <?php echo $form->dropDownList(
        $model,
        'province',
        $model->getProvinceList(),array('empty'=>'-请选择-',
            'ajax'=>array(
                'url'=>Yii::app()->createUrl('member/dynamicCity'),       
                'data'=>array('pid'=>'js:this.value'),
                'update'=>'#Member_city',
            ),
                                                     )
                                                ); ?>
        <?php echo $form->error($model,'province'); ?>
</div>
  • 回复于 2012-01-03 22:05 举报

    http://www.yiichina.com/topic/614
    二级联动下拉菜单。

  • 回复于 2012-01-03 22:05 举报

    为什么贴出来排版这么奇怪呢?
    不管了,事情是这样的,这段代码是舰长在省份城市两级连动中的根据省份自动生成城市list的代码,用到了AJAX.我有以下几点不清楚,
    a. 如果是module Issue中IssueController中的函数actionDynamicProjectNumber,是否应该改写成'url'=>Yii::app()->createUrl('Issue/issue/dynamicProjectNumber'),
    b. 'update'=>'#Member_city',
    是什么含义啊?

  • 回复于 2012-01-03 22:07 举报

    多谢舰长提醒,我看的就是这段代码,想改写,没改成功

  • 回复于 2012-01-03 22:08 举报
    public static function ajax($options)
    {
        Yii::app()->getClientScript()->registerCoreScript('jquery');
        if(!isset($options['url']))
            $options['url']='js:location.href';
        else
            $options['url']=self::normalizeUrl($options['url']);
        if(!isset($options['cache']))
            $options['cache']=false;
        if(!isset($options['data']) && isset($options['type']))
            $options['data']='js:jQuery(this).parents("form").serialize()';
        foreach(array('beforeSend','complete','error','success') as $name)
        {
            if(isset($options[$name]) && strpos($options[$name],'js:')!==0)
                $options[$name]='js:'.$options[$name];
        }
        if(isset($options['update']))
        {
            if(!isset($options['success']))
                $options['success']='js:function(html){jQuery("'.$options['update'].'").html(html)}';  //这里是update产生的js代码。
            unset($options['update']);
        }
        if(isset($options['replace']))
        {
            if(!isset($options['success']))
                $options['success']='js:function(html){jQuery("'.$options['replace'].'").replaceWith(html)}';
            unset($options['replace']);
        }
        return 'jQuery.ajax('.CJavaScript::encode($options).');';
    } 
    
  • 回复于 2012-01-03 22:10 举报

    谢谢舰长,先好好看看,再来问问

  • 回复于 2012-01-06 09:40 举报

    老大帮我看看到底什么地方出问题了,我重新写过一遍你的DemoCity,细节都注意到,而且成功了。
    但是想把这个结构应用到我这里来的时候就出问题了,报错PHP500

    /*
     *  Give Dynamic Project Number List
     * 
     */
    public function actionDynamicProjectNumber($machine_sn)
    {
    //    $model=Machine::model()->getMachineSnList();
          $model = Issue::model()->getProjectNumberList($machine_sn);
    //    $model=Machine::model()->getMachineSnList1();               
             foreach($model as $value=>$name) 
             {
              echo CHtml::tag('option',array('value'=>$value),CHtml::encode($name),true);
                                         }
     }
    <!-- machine _ s n drop down list-->
    <div class="row">
    <?php echo $form->labelEx($model,'machine_sn'); ?>
    <?php 
         echo $form->dropDownList(
                       $model,
                       'machine_sn', 
                       Issue::model()->getMachineSnList(),
                       array(
                             'empty'=>'-请选择-',
                             'ajax'=>array(
                                  'url'=>Yii::app()->createUrl('Issue/issue/dynamicProjectNumber'),                                                      
    			      'data'=>array('machine_sn'=>'js:this.value'),
                                  'update'=>'#Issue_project_number',
                                   ),
                                 )
                              );                                                
                                        ?>
    <?php echo $form->error($model,'machine_sn'); ?>
    </div>
    array('allow',          // allow authenticated user to perform 'create' and 'update' actions
    	 'actions'=>array('create','update','dynamicProjectNumber'),
    	  'users'=>array('@'),
    			), 
    public function getMachineSnList () {
          $currMachineSnList=  Machine::model()->findAll();
          return cHtml::listData($currMachineSnList,'machine_sn','machine_sn');
           }
                     
     /*
      *  get Machine Project Number
      * 
      */
     public function getProjectNumberList ($machine_sn) {
           $currProjectNumber=  Machine::model()->findAllByAttributes(array('machine_sn'=>$machine_sn));
           return cHtml::listData($currProjectNumber,'machine_sn','project_number');
            }
    
  • 回复于 2012-01-06 09:59 举报

    然后在跑的时候能够执行actionDynamicProjectNumber,但是不能通过,会报错[attach]581[/attach]

  • 回复于 2012-01-06 10:14 举报

    PHP Error [2]

    include(cHtml.php) [function.include]: failed to open stream: No such file or directory (D:\xampp\htdocs\X\framework\YiiBase.php:421)

    #0 D:\xampp\htdocs\X\framework\YiiBase.php(421): CWebApplication->handleError()
    #1 D:\xampp\htdocs\X\framework\YiiBase.php(421): autoload()
    #2 unknown(0): autoload()
    #3 D:\xampp\htdocs\X\yii_fox\protected\models\Issue.php(111): spl_autoload_call()
    #4 D:\xampp\htdocs\X\yii_fox\protected\modules\Issue\controllers\IssueController.php(184): Issue->getProjectNumberList()
    #5 unknown(0): IssueController->actionDynamicProjectNumber()
    #6 D:\xampp\htdocs\X\framework\web\actions\CAction.php(104): ReflectionMethod->invokeArgs()
    #7 D:\xampp\htdocs\X\framework\web\actions\CInlineAction.php(48): CInlineAction->runWithParamsInternal()
    #8 D:\xampp\htdocs\X\framework\web\CController.php(300): CInlineAction->runWithParams()
    #9 D:\xampp\htdocs\X\framework\web\filters\CFilterChain.php(134): IssueController->runAction()
    #10 D:\xampp\htdocs\X\framework\web\filters\CFilter.php(41): CFilterChain->run()
    #11 D:\xampp\htdocs\X\framework\web\CController.php(1144): CAccessControlFilter->filter()
    #12 D:\xampp\htdocs\X\framework\web\filters\CInlineFilter.php(59): IssueController->filterAccessControl()
    #13 D:\xampp\htdocs\X\framework\web\filters\CFilterChain.php(131): CInlineFilter->filter()
    #14 D:\xampp\htdocs\X\framework\web\CController.php(283): CFilterChain->run()
    #15 D:\xampp\htdocs\X\framework\web\CController.php(257): IssueController->runActionWithFilters()
    #16 D:\xampp\htdocs\X\framework\web\CWebApplication.php(277): IssueController->run()
    #17 D:\xampp\htdocs\X\framework\web\CWebApplication.php(136): CWebApplication->runController()
    #18 D:\xampp\htdocs\X\framework\base\CApplication.php(158): CWebApplication->processRequest()
    #19 D:\xampp\htdocs\X\yii_fox\index.php(13): CWebApplication->run()
    
  • 回复于 2012-01-06 10:30 举报

    指向报错的地方是jquery.js的下面这段代码

    // Do send the request
    // This may raise an exception which is actually
    // handled in jQuery.ajax (so no try/catch here)
    xhr.send( ( s.hasContent && s.data ) || null );
    
  • 回复于 2012-01-06 16:38 举报

    解决了,我把相应的model,module,view,controller删除后重新做了一遍就好了

  • 回复于 2012-01-06 16:39 举报

    不过百思不得其解的时候就应该换种思路,也许死在哪个细节上都不知道

  • 回复于 2012-02-02 17:16 举报

    二级联动学习啦

  • 回复于 2012-02-04 10:53 举报

    对头,有时候可能是因为缓存或者其他什么客观原因导致,也有时候多刷新几次就ok了,但我碰到这类ajax最多的问题是ajax调用方法的权限问题导致!

您需要登录后才可以回复。登录 | 立即注册