Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 提交表单后如何显示下拉菜单筛选选定值?_Javascript_Php_Forms_Yii - Fatal编程技术网

Javascript 提交表单后如何显示下拉菜单筛选选定值?

Javascript 提交表单后如何显示下拉菜单筛选选定值?,javascript,php,forms,yii,Javascript,Php,Forms,Yii,我正在开发一个带有下拉菜单过滤器的搜索表单。这个网站是由Yii创建的 我的筛选表单在提交之前是这样的:pic1 当我选择过滤器时形成:pic2 但是在我点击filter按钮之后,它又像这样出现:PIC3 但是我希望在我提交表格显示结果后,表格应保持为pic2 我的表格是: <div class="row"> <div style="float: left"> <label class="form_controller required"

我正在开发一个带有下拉菜单过滤器的搜索表单。这个网站是由Yii创建的

我的筛选表单在提交之前是这样的:
pic1

当我选择过滤器时形成:
pic2

但是在我点击
filter
按钮之后,它又像这样出现:
PIC3

但是我希望在我提交表格显示结果后,表格应保持为
pic2

我的表格是:

<div class="row">
    <div style="float: left">
        <label class="form_controller required">By Brand</label>

        <select style="width: 148px;" id="select_options" name="SCDcustomer_contacts_cms[brand_select_option]">
            <option value="none">Select an option</option>
            <option value="brand_preference">Brand Preference</option>
            <option value="brand_purchased">Brand Purchased</option>
        </select>
    </div>
    <div id="select_a_brand" name="select_a_brand"> 
        <?php echo $form->dropDownList($model,'brand_id', gGetBrandList('brand_id', 'brand_id, brand_name'), array('prompt'=>'Select a brand')); ?> 
    </div>

    <script type="text/javascript">
        $(document).ready(function(){
            jQuery('#select_a_brand').hide();

            $("#select_options").change(function(){
                $( "select option:selected").each(function(){

                    if(($(this).attr("value")=="brand_preference") || ($(this).attr("value")=="brand_purchased") ){                                 
                        $("#select_a_brand").show();
                    }

                    if($(this).attr("value")=="none"){                                  
                        $("#select_a_brand").hide();
                    }

                });
            });
        });
    </script>
</div>
表单筛选器为:

if(!empty($filter)) {
    if ($this->brand_select_option == "brand_preference") {
                $criteria->select .= ', COUNT(*) as brand_preference';              
                $criteria->join .= ' INNER JOIN order_table ot ON ot.billing_contactid = t.contactid';
                $criteria->join .= ' INNER JOIN order_item oi ON ot.scd_order_id = oi.scd_order_id';        
                $criteria->join .= ' INNER JOIN johnanthony_rstest.product p ON p.product_id = oi.product_id';
                $criteria->condition .= (!empty($criteria->condition) ? ' AND ' : '') . 'p.brand_id=:brand_id';
                $criteria->group = 't.contactid';
                $criteria->order = 'COUNT(*) DESC';
                $criteria->params = array(':brand_id'=>$this->brand_id);
                $paging['pagination']['route']='report/index?SCDcustomer_contacts_cms[brand_id]=' . $this->brand_id;//For ajax pagination URL
            }

            if ($this->brand_select_option == "brand_purchased") {
                $criteria->select .= ', SUM(product_price) AS brand_purchased';    
                $criteria->join .= ' INNER JOIN order_table ot ON ot.billing_contactid = t.contactid';
                $criteria->join .= ' INNER JOIN order_item oi ON ot.scd_order_id = oi.scd_order_id';  
                $criteria->join .= ' INNER JOIN johnanthony_rstest.product p ON p.product_id = oi.product_id';
                $criteria->condition .= (!empty($criteria->condition) ? ' AND ' : '') . 'p.brand_id=:brand_id';
                $criteria->group = 't.contactid';
                $criteria->order = 'SUM(product_price) DESC';
                $criteria->params = array(':brand_id'=>$this->brand_id);
                $paging['pagination']['route']='report/index?SCDcustomer_contacts_cms[brand_id]=' . $this->brand_id;//For ajax pagination URL
            }
 }
Ajax文件是:

if (!empty($model->brand_id) && ($model->brand_select_option == "brand_preference")) {
    array_push($options['columns'], array(
        'name'=>'brand_preference',
        'filter'=>false,
        'header'=>'Brand Preference (No of purchased items)',
        'type'=>'raw',
        'value'=>'$data->brand_preference',

    )); 
}
if (!empty($model->brand_id) && ($model->brand_select_option == "brand_purchased")) {
    array_push($options['columns'], array(
        'name'=>'brand_purchased',
        'filter'=>false,
        'header'=>'Brand Purchased (Sum of purchased items)',
        'type'=>'raw',
        'value'=>'$data->brand_purchased',

    )); 
}

每次单击按钮过滤器时,您似乎都在加载页面,如果您使用Ajax,则无需回发即可访问此单击事件,或者如果您必须以最简单的方式刷新页面,只需保存在执行过滤器事件按钮之前选择的下拉菜单索引,当您再次加载页面时,您只需将下拉菜单传递给您,在加载页面时需要选择索引。我希望这会对您有所帮助。

主要问题是DOM刷新页面,因为可能会定期提交。没有submit方法就不能说得更具体。如果您使用ajax,您将在json数据保持器中获得所有数据。然后将其解析为对象和html所需的部分,以显示结果。所有过滤等都必须在模型中进行。控制器仅将值传递给它

将过滤器按钮设为ajaxButton:


谢谢你。是 啊我想在提交页面时刷新页面,因为我想显示结果。同时我想显示选定的过滤器<代码>保存在您执行筛选事件按钮之前选择的下拉菜单索引,当您再次加载页面时,您只需将带有索引的下拉菜单传递给您。加载页面时,需要选择索引。
根据上面的代码,我如何才能做到这一点。我很困惑,谢谢你。这应该是解决办法。但我不能只是照搬过去然后开始工作。我犯了一个错误。我把这样的代码放在我的表单中,而不是按钮中:我得到了这样的错误:`Parse error:syntax error,意外的T_CONSTANT_ENCAPSED_STRING,expecting'),在/var/www/vhosts/rstest.john-anthony.com/httpdocs/protected/modules/admincms/views/report/index.php的第86行,这不会像示例中所示那样工作。首先,我怀疑您是否有div或任何其他带有id#search result holder的html标记(这应该是您对结果进行html处理的地方)。在视图中,您应该通过renderPartial(“报告/额外视图文件夹/搜索结果”,数组('model'=>$model),true)返回控制器或其他视图中生成的html数据;将render partial分配给某个变量,并回显CJSON::encode(数组('search-results'=>$assigned_to_renderPartial_variable));当然,在此之前,您必须将brand_id(SCDcustomer_contacts_cms[brand_id])传递给属性。我的视图文件(httpdocs\protected\modules\admincms\views\report\index.php)的结尾如下:我的ajax文件(httpdocs\protected\modules\admincms\views\report_ajaxContent.php)是:查看第50行
if (!empty($model->brand_id) && ($model->brand_select_option == "brand_preference")) {
    array_push($options['columns'], array(
        'name'=>'brand_preference',
        'filter'=>false,
        'header'=>'Brand Preference (No of purchased items)',
        'type'=>'raw',
        'value'=>'$data->brand_preference',

    )); 
}
if (!empty($model->brand_id) && ($model->brand_select_option == "brand_purchased")) {
    array_push($options['columns'], array(
        'name'=>'brand_purchased',
        'filter'=>false,
        'header'=>'Brand Purchased (Sum of purchased items)',
        'type'=>'raw',
        'value'=>'$data->brand_purchased',

    )); 
}