Yii 1.1.3设置从属下拉部分2的选定值 [英] Yii 1.1.3 setting selected value of dependent dropdown part 2
问题描述
以前,我创建了一个问题我想知道如何设置从属下拉列表的选定值。这很容易,人建议我设置第二个参数。
Previously I've created a question where I was wondering how to set selected value for dependent dropdown. That was easy, man adviced me just set second parameter.
echo CHtml::dropDownList('OpenLessons[Building]', $buildingClassID, $buildingList,array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('ajax/floorList'),
'update'=>'#OpenLessons_Floor',
)));
echo CHtml::dropDownList('OpenLessons[Floor]',$model->Class_ID, array(),array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('ajax/roomList'),
'update'=>'#OpenLessons_Class_ID',
)));
echo CHtml::dropDownList('OpenLessons[Class_ID]',$model->Class_ID, array());
其中 $ buildingClassId
是select的值。所以这样工作正常的第一选择。但是,如何为依赖设置相同?当我看着它的代码看起来像这样:
where $buildingClassId
is value of select. So that works fine for first select. But how can I set the same for dependent ones? When I look at it's code it looks like this:
<select name="OpenLessons[Floor]" id="OpenLessons_Floor">
</select>
我预计它有一些选项,因为我为第一个设置默认值。所以即使我把第二个参数作为第二个参数,一些值不会被选中。
任何建议/建议?
更新我会提到我在XHR控制面板上看不到楼层列表。我该怎么做?
更新
I expected it to have some options, because I set default value for first one. So even if I put as second parameter of seconddropdown some value it wouln't be selected.
Any advices/suggestions?
UPDATE I'd mention that I don't see at XHR console call of floorlist. How can I make it?
UPDATE
$(document).ready(function()
{
$('#OpenLessons_Building').trigger('change');
$('#OpenLessons_Building option').trigger('click');
}).on('change','#OpenLessons_Building',function()
{
console.log('changed');
}).on('click','#OpenLessons_Building option',function()
{
console.log('clicked');
});
尝试这样。发生了两个动作 - 改变和点击,因为我可以在控制台中看到输出,而依赖的数组仍然是空的。
Tried like this. Both actions - change and click has happened because I can see output in console, but the dependent arrays are still empty.
推荐答案
你应该使用$(#OpenLessions_Building)。on(change,function(){your code here});
You should use $("#OpenLessions_Building").on("change", function() { your code here });
触发功能实际上是在页面加载后立即执行下拉列表中的操作(更改或单击)。
The trigger function was actually does is execute the action (change or click in your case) of the dropdown as soon as the page loads.
这篇关于Yii 1.1.3设置从属下拉部分2的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!