I want to pass object in data context in route. I am trying to read JavaScript object(which holds the business logic) . If i send the object as such , then i can read it's properties in template. But if i try to send a custom object by reading some of it's properties . Then I am getting error that it can not read properties of same object.
this.route('updateBook/' ,
{
path:'/updateBook',
loadingTemplate: 'loading',
data : function(){
var Book = Books.findOne({hasFinished:true});
var UpdateBookObject ={};
//UpdateBookObject.currentPage = Book.currentPage;
UpdateBookObject.name = Book.name;
UpdateBookObject.author = Book.author;
// UpdateBookObject.img = Book.img;
UpdateBookObject.numOfPages = Book.numOfPages;
UpdateBookObject.dateStarted = Book.dateStarted;
UpdateBookObject.dateToFinish = Book.dateToFinish;
UpdateBookObject.percentage = (UpdateBookObject.currentPage/UpdateBookObject.numOfPages).toFixed(2);
UpdateBookObject.pagesRemaining = UpdateBookObject.numOfPages - UpdateBookObject.currentPage;
var finishMoment = moment(UpdateBookObject.dateToFinish,"DD-MM-YYYY");
var startMoment = moment(UpdateBookObject.dateStarted,"DD-MM-YYYY");
UpdateBookObject.perDayToRead = finishMoment.diff(startMoment,'days');
return UpdateBookObject;
}
});
Aucun commentaire:
Enregistrer un commentaire