很难让这个工作。使用 Chrome javascript 控制台,我可以看到我的函数正在触发并得到我需要的结果,它只是不会填充多选。这是代码:
jQuery:
$("select[name='field[one]']").change(function()
{
var optionValue = $("select[name='field[one]']").val();
$.get
('/directory/location/getData', {select:optionValue},
function(data)
{
$("select[name='subjects']").val(data);
}
);
}
);
HTML:
<select name="field[one]" id="field_one">
<option value="" selected="selected"></option>
<option value="2011">2011</option>
</select>
<select multiple id="show_results" name="subjects" />
</select>
AJAX PHP 调用:
public function executeGetData(sfWebRequest $request){
$year = $request->getParameterHolder()->get('select');
$specialties = Doctrine_Core::getTable('Specialty')->getSpecialtyArray();
$array = array();
foreach($specialties as $specialty){
$array[$specialty['id']] = '';
$count = Doctrine_Core::getTable('HistoricalSalaries')->getCountPerSpec($year, $specialty['id']);
$array[$specialty['id']] .= $specialty['name']." Count($count)";
}
return $this->renderText( json_encode( $array ) );
}
结果是一个json编码的数组......我认为这是问题......让多重选择正确解释该信息。目前,在拨打电话并检索数据后没有任何反应。
以下是 chrome 调试器中显示的 json 编码数组结果示例:
{
2: "Aerospace Medicine Count(50)",
3: "Abdominal Radiology (DR) Count(65)",
4: "Addiction Psychiatry (P) Count(46)",
5: "Adolescent Medicine (PD) Count(23)"
}
提前致谢。