I can not find the error in my arrangement. I have the following function.
I get this message in my combobox:
data: arrayCuadroFuerzaGrid.LISTA (Uncaught TypeError: Cannot read property 'LISTA' of undefined)
This is my function:
public function listarCuadroFuerzaGrid($planta = NULL,$sitio = NULL)
{
$cond_planta = "";
if (!empty($planta) ) {
$cond_planta = "where inv.idplanta = $planta";
}
$cond_sitio = "";
if (!empty($sitio) ) {
$cond_sitio = "where inv.idsitio = $sitio";
}
$sql = "SELECT distinct inv.idcuadrofuerza, cf.descuadrofuerza FROM inventario AS inv
LEFT JOIN cuadro_fuerza AS cf ON (inv.idcuadrofuerza = cf.idcuadrofuerza)
WHERE inv.idcuadrofuerza <>0 AND $cond_planta AND $cond_sitio";
$data = ModeloConexion::ejecutar( $sql , DB_NAME , DB_SELECT );
$resultado = array();
$resultado['TOTAL'] = $data['TOTAL'];
$resultado['REGISTROS'] = $data['REGISTROS'];
$respuesta = array();
for($i=0; $i<$data['TOTAL']; $i++){
$rp = new stdClass();
$rp->id = $data['LISTA'][$i]->idcuadrofuerza;
$rp->nombre = $data['LISTA'][$i]->descuadrofuerza;
$respuesta[] = $rp;
}
$resultado['LISTA'] = $respuesta;
header('Content-type: application/json');
echo json_encode($resultado);
}
I call it this way:
$.ajax({
type: "POST",
url: '../php/ajax.php?opcion=listarCuadroFuerzaGrid',
dataType: 'json',
data: {
idplanta : planta,
idsitio : idsitio
},
success: function(data) {
arrayCuadroFuerzaGrid = data.LISTA || [];
var combo = Fancy.getWidget('g_idcuadrofuerza');
combo.setData(data.LISTA);
combo.setValue(item.cuadrofuerza);
}
});
This is my combobox:
type: 'combo',
width:110,
editable: false,
name: 'g_idcuadrofuerza',
id: 'g_idcuadrofuerza',
emptyText: 'Seleccione',
data: arrayCuadroFuerzaGrid.LISTA,
displayKey: 'nombre',
valueKey: 'id',
value: 0