我有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
,如何合并两个链接并将它们创建为一个?。任何帮助和建议都将高度赞赏。
答案 0 :(得分: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
)
)
);
答案 1 :(得分: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;',
));
?>
添加bellow jquery
$('#city_name').change(function() {
if($(this).val() != ""){
window.location.assign('<?php echo Yii::app()->createUrl('city/view'); ?>' + '?id=' + $(this).val());
}
});