lundi 28 avril 2014

Bootstrap Mongoose.js Model data to Backbone.js Model, render in Handlebars


Vote count:

0




I have a Mongo db set up on Express and am using Passport to authenticate and register users. Everything worked as planned until I tried to bootstrap the data and render the views with Backbone. Here is the Backbone Model I have to pull data from db:



var UserMongooseModel = Backbone.Model.extend({
urlRoot: '/users',
idAttribute: "_id",
defaults: {

_id : '535947a52400be56922359c7',
__v: 0,
local: {
password: "$2a$08$aGl4FCFsWO9Nu97U3hgQtOf.YWBWmSTRbPYBWvriM9tELORwfpEWi",
email: "melmcg@gmail.com",
petName: "Smeagol"
}


}

});


My express server set up is working because the following code DOES fetch the data from the database:



//user model
this.userMongooseModel = new UserMongooseModel();
console.log(this.userMongooseModel.fetch());


But my handlebars view will only render the default data from the backbone model and NOT the model I want it to fetch.



var AuthProfileView = Backbone.View.extend({

template: Handlebars.compile(
'<div class="container">' +
'<h1><span class="fa fa-anchor"></span> Kitten Profile Page</h1>' +
'<a href="/logout" class="btn btn-default btn-sm">Logout</a>' +
'</div>' +
'<div class="row">'+
'<div class="col-sm-6">' +
'<div class="well">' +
'<h3><span class="fa fa-user"></span> Local</h3>' +
'<p>'+
'<strong>id</strong>: {{id}}<br>' +
'<strong>email</strong>: {{local.email}}<br>' +
'<strong>password</strong>: {{local.password}}<br>' +
//'<strong>password</strong>: {{local.petName}}<br>' +

'</p>' +
'</div>' +
'</div>'+
'</div>'
),

initialize: function() {
this.listenTo(this.model, "change", this.render );
},

render: function() {

this.$el.html(this.template(this.model.attributes));
return this;
}

});


What did I miss?? Thank you.


here is Mongoose Schema if it helps:



var userSchema = mongoose.Schema({


local : {
email : String,
password : String,
petName : String,
}
});


asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire