Code error fixed #7: Returning Parse database class query data via Underscore template

Haven’t had time to note #5 and #6 but skipped to #7 in the hope that I’ll revisit those. But compelled to record #7, because it epitomizes my perseverance in learning this stuff. My project must have a browse feature. The splash page has had one prominent button that says “Browse”, after all. But it was starting to look like it might not, because my attempts at rendering Parse data via an Underscore template were failing, and I got sidetracked by design issues. (I needed to focus on some design issues, yes. But this browse feature got tossed aside along with this unresolved programming dilemma.)

So, I won’t rationalize why I tried each of these, and this is just a sampling. I can’t recall. But I only had so many prior working examples in projects, and the internet doesn’t have a whole lot of examples. And I’m pulling from a Parse database, for whatever that’s worth.

$('#browse-container').append(_.template(browseView),results[i]);

Result:
No error, but no data returned.

$('#browse-container').append(_.template(browseView),results[i].attributes);

Result:
(where petname is one of the properties I’m trying to return from a class called Pet)

ReferenceError: petname is not defined

$('#browse-container').append(_.template(browseView),JSON.stringify(results[i]));

Result:
ReferenceError: petname is not defined

$('#browse-container').append(_.template(browseView),JSON.stringify(results[i].attributes));

Result:
ReferenceError: petname is not defined

$('#browse-container').append(_.template(browseView,JSON.stringify(results[i].attributes)));

Result:
ReferenceError: petname is not defined

Finally…what worked
$('#browse-container').append(_.template(browseView,results[i].attributes));

I never would have went astray with the JSON.stringify syntax had I, days ago, simply realized what was essentially a typo of an errant parenthesis, but it was one of those errors where the parenthesis wasn’t what was throwing any error.

Anyway, moving on…

meta-blogging note: I must get off of this theme and wordpress.com or pay to be able to customize. This looks horrible.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s