I am facing a challenge with accessing backbone views within the sails framework. After fetching data from the server, I am attempting to push it to the DOM. I have set up a model-controller for the tags where I store data from Mongo into the tags model and return the URL of the tags view to Backbone. My goal is to display this data in my DOM element. However, I am encountering an error stating that 'tagsCloud is not defined'. Below is the code snippet related to my DOM element:
51| <div id="profiles" class = 'hashTagsCloud'>
52| <script id="profileTemplate" type="text/template">
>> 53| <%= tagsCloud.tags.join("     ")%>
54| </script>
55| </div>
tagsCloud is not defined
The 'tagsCloud' variable is part of the JSON file received from the server which contains the data. The Backbone code for the views is as follows:
var ProfileView = Backbone.View.extend({
el: "#profiles",
template: _.template($('#profileTemplate').html()),
render: function(eventName) {
_.each(this.model.models, function(profile){
var profileTemplate = this.template(profile.toJSON());
//push data to obj for map script
obj = profile.toJSON();
// Add data to DOM element
$(this.el).html(profileTemplate);
}, this);
return this;
}
});
This backbone logic works flawlessly in Apache, but encounters errors in Sails. How can I properly define a view for the 'tagsCloud' item in my index file within Sails? Here is a snippet of the JSON file being used:
[
{
tstamp: 1366626103000,
tagsCloud: {
sort: "asc",
tags: [
"Lorem ipsum dolor sit amet consectetur"
]
},
id: "529da369380eb213e804a673"
}
]
In addition, I have made some modifications to my homeController file in order to send the JSON data to the EJS file:
index: function (req,res)
{
console.log(req.tags); // tags is the name of the model-controller
res.view({
tags: req.tags
});
},
'home': function (req,res)
{
res.view();
}
Is there anything specific that needs to be adjusted in the Backbone view code to correctly update my index view?