1

我有这样的dropdown清单

   <?php echo $form->dropdownList($customers,'customer_name', CHtml::listData(Customers::model()->findAll(), 'id', 'customer_name'),
 array(
   'ajax'=> array(
             'type'=>'GET',
             'url'=>
             'data'=>
           ),
             'empty'=>--Select One---')); ?>

创建一个的另一个链接new customer是这样的

 <?php echo CHtml::link('Create Customers', "",array(
        'style'=>'cursor: pointer; text-decoration: underline;',
        'onclick'=>"{addCustomers(); $('#dialogCustomers').dialog('open');}"));?>

我想要create customer link应该进来dropdown list。那么如何放置create customer link inside the dropdown list,如何合并两个链接并将它们创建为一个链接?任何帮助和建议都将非常受欢迎。

4

2 回答 2

1

Tbh我不太确定你想要做什么,但从我得到的你需要这样的东西:

echo $form->dropDownList(
    $customers,
    'customer_name',
    CMap::mergeArray(
        CHtml::listData(
            Customers::model()->findAll(), 'id', 'customer_name'
        ),
        array(
            'create_customer_link'=>'Create new customer'
        )
    ),
    array(
        'empty'=>array('Select'=>'--Select One---'),
        'id'=>'Customers_name',
        'ajax'=> array(
            'type'=>'GET',
            'beforeSend'=>'js:function(){
                if($("#Customers_name").val() == "create_customer_link") {
                    addCustomers();
                    $("#dialogCustomers").dialog("open");
                    return false;
                }
            }',
            'url'=>...
            'data'=>...
        ),
        'options'=>array(
            'create_customer_link' => array('class'=>'my_custom_css_class'),
            // ... etc. You can add any html option here.
            // check http://www.yiiframework.com/doc/api/1.1/CHtml#dropDownList-detail for more info
        )
    )
);
于 2012-04-07T02:50:30.913 回答
0

如果我理解你的要求。您想在下拉列表的选项上添加链接。这是执行此操作的简单方法。

                    <?php 
                      echo CHtml::dropDownList('city_name', null,
                        $arrPopularCities, 
                        array(
                            'prompt' => 'Popular City',
                            'class' => 'btn btn-default btn-dropdown dropdown-toggle',
                            'style' => 'border-right:2px solid #4bacc6;',
                        )); 
                ?>

添加波纹管jQuery

    $('#city_name').change(function() {
    if($(this).val() != ""){
        window.location.assign('<?php echo Yii::app()->createUrl('city/view'); ?>' + '?id=' + $(this).val());
    }
});
于 2015-05-29T11:18:29.733 回答