how to change values of object in controller

33 views
Skip to first unread message

JBD

unread,
Jun 8, 2015, 3:37:03 PM6/8/15
to nod...@googlegroups.com
Hi.

I am trying to loop through an array and change the value of a field in a node.js controller.  How do I do this?

item.fetch({
onerror: function() {
res.status(404).end();
},
success: function() {
var e = item.toJSON();
for (var i in e) {
e.OurRating = e.OurRating*10).toFixed(0);;
}
viewData.Item = e;
render(req, res, 'page', viewData);
}
});

Ryan Schmidt

unread,
Jun 9, 2015, 12:33:05 AM6/9/15
to nod...@googlegroups.com

On Jun 8, 2015, at 12:56 PM, JBD wrote:

> I am trying to loop through an array and change the value of a field in a node.js controller. How do I do this?
>
> item.fetch({
> onerror: function() {
> res.status(404).end();
> },
> success: function() {
> var e = item.toJSON();
> for (var i in e) {
> e.OurRating = e.OurRating*10).toFixed(0);;

Here, did you mean "i.OurRating" instead of "e.OurRating"?

Of course, you've got other typos, like the mismatched close parenthesis and the second trailing semicolon.

JBD

unread,
Jun 10, 2015, 11:21:34 PM6/10/15
to nod...@googlegroups.com
Yes, var item = e[i].OurRating; was the answer, thanks.
Reply all
Reply to author
Forward
0 new messages