i had a project contains many problems and i want to get one problem with findOne not all the problems in this project can someone correct for me my code.
this requete ajax which display for me all problems of this project
<div id="people"></div>
<script type="text/javascript">
var data;
var id = "<%= id %>";
var problemes = [];
$.ajax({
url : "/projets/"+id+"/ajax",
data : data,
cache : false,
dataType : "json",
error : function(request, error) {
alert("Erreur : responseText: "+request.responseText);
},
success : function(data) {
data = data.problemes;
data.forEach(function(element) {
var obj = {
id: element._id,
parentId:null,
name:element.text
}
problemes.push(obj);
});
console.log('aa0', problemes);
console.log('aa', problemes);
var peopleElement = document.getElementById("people");
var orgChart = new getOrgChart(peopleElement, {
color: 'FF0000',
primaryFields: ["name", "title"],
photoFields: ["image"],
dataSource: problemes
});
}
});
</script>
and this a route which returns a json data
router.get("/:id/ajax", function(req, res){
Projet.findById(req.params.id).populate("problemes").exec(function(err, data){
console.log("data", data);
if(err){
console.log(err);
} else {
res.status(200).json(data);
}
});
});