I have already added the package:
dburles:collection-helpers
My question is:
why a findOne();
inside a helper
of the other collection
don’t work?
- The first
console.log();
it works! but it bring me all catalog, and, I don’t want read all values to obtain that I need it, because is not optimum, because I save the ID’s in mycollection vacantes
, and not the descriptions of the catalogs. - The second
console.log();
I want obtain the description from a catalog, and I needfindOne();
but it sendmeundefined
Next my codes:
///// collection.js
import {Mongo} from 'meteor/mongo';
import {Puestos} from '../puestos/collection';
export const Vacantes = new Mongo.Collection('vacantes', {});
Vacantes.deny({
insert() {return true;},
update() {return true;},
remove() {return true;},
});
Vacantes.helpers({
puestoDesc(){
// Works! but, obtaining everything
console.log('Helper description of the puesto', Puestos.find({_id: this.puestoId}));
// this is undifined why?
console.log('Helper description of the puesto', Puestos.findOne({_id: this.puestoId}));
return 'Here I want return a object property' this.puestoId;
}
});
///// html
This is my client html code, it describes how that I invoke it:
In the client code: ng-init="puestoDesc = vacante.puestoDesc();
the helper from collection vacantes run!, but the findOne();
is not obtained nothing.
<li class="list-group-item"
ng-repeat="postulacion in postEnproceso.misPostulaciones"
ng-init="vacante = postEnproceso.verVacante(postulacion.vacanteId)">
<div class="row">
...some code
</div>
<h5 class="list-group-item-heading" ng-init="puestoDesc = vacante.puestoDesc()">
Postulada para - {{cadenaDesc}} ({{vacante.sucursal}})
Puesto: {{puestoDesc}}, Marca: {{vacante.marca}},
Estado: {{estadoDesc}} {{vacante.sueldo | currency}} x día
</h5>
<p class="list-group-item-text">
Publicaca: {{vacante.fechaCreacion | date : format : dd/MM/YYYY}} -
Postulada: {{postulacion.fechaPostulacion | date : format : dd/MM/YYYY}}
</p>
</li>
///// js from my client
.. imports
.. imports
class PostEnproceso {
constructor($scope, $reactive) {
'ngInject';
$reactive(this).attach($scope);
this.subscribe('postulaciones.mis', ()=> [{estado:1}]);
this.helpers({
misPostulaciones() {
return Postulaciones.find();
}
});
}
verVacante(id){
console.log('verVacante', id);
return Vacantes.findOne({_id:id});
}
}
const name = 'postEnproceso';
// Módulo
export default angular
.module(name, [
angularMeteor,
uiRouter
])
.component(name, {
templateUrl: `imports/ui/components/misPostulaciones/${name}/${name}.html`,
controllerAs: name,
controller: PostEnproceso
})
.config(config);