我的 foreach 出现问题,说“为 foreach 提供的参数无效......”
这是我正在处理的代码:
protected function jsGenerateResourcesAutocomplete(){
$employeeNames = $this->employeeNames;
$html = "";
$html .= '<script>' . PHP_EOL;
$html .= 'var employeeNames = [' . PHP_EOL;
foreach( $employeeNames as $employeeName ){
$html .= '"' . $employeeName->getEmployeeName() . '",' . PHP_EOL;
}
$html .= '];' . PHP_EOL;
$html .= '$(function() {' . PHP_EOL;
$html .= '$(#resource-input input:text").each(function() {' . PHP_EOL;
$html .= '$(this).autocomplete({source: employeeNames});' . PHP_EOL;
$html .= '})' . PHP_EOL;
$html .= '})' . PHP_EOL;
$html .= '</script>' . PHP_EOL;
return $html;
}
在这一行中:foreach( $employeeNames as $employeeName ){抛出错误。这有什么问题?