backbone.js - MarionetteJS - Not able to render the data using toJSON function -
i using handlebarsjs
plugin render templates. getting error while call rendering function.
when console this.model.tojson()
, getting correct datas, console "homeedittemp" getting templates too..
but when pass data template getting error : uncaught typeerror: undefined not function
here code :
define([ 'jquery', 'underscore', 'backbone', 'marionette', 'hbs!scripts/templates/home/homeedittemp'], function ($,_,backbone, marionette, homeedittemp) { "use strict"; window.socialapp = window.socialapp || {}; socialapp.homeview = backbone.marionette.itemview.extend({ initialize : function (model) { this.model = model; }, render : function () { console.log(this.model.tojson()) // works fine console.log(homeedittemp) // works fine. this.$el.html(homeedittemp(this.model.tojson())); // throws error.. } }); return socialapp.homeview; });
here handlebars
template :
<form> <div class="control-group"> <label for="firstname" class="control-label"> first name:</label> <input id="firstname" name="firstname" type="text" value="{{firstname}}"/> </div> <div class="control-group"> <label for="lastname" class="control-label"> last name:</label> <input id="lastname" name="lastname" type="text" value="{{lastname}}"/> </div> <div class="control-group"> <label for="email" class="control-label">phone number:</label> <input id="email" name="email" type="text" value="{{email}}"/> </div> <button class="btn js-submit">save</button> </form>
thanks in advance!
update :
when manually assign value, works fine this:
render : function (model) { var obj = { "firstname" : "testfirstname ", "lastname" : " test lastname" } this.$el.html(homeedittemp(obj)); }
what issue?
when console model show this:
object {model: s}model: s_changing: false_events: object_pending: false_previousattributes: objectattributes: objectchanged: objectcid: "c6"__proto__: n__proto__: object
at first need compile template
var tpl = function () { return handlebars.compile(homeedittemp); }
then can use this
this.$el.html(tpl(this.model.tojson()));
Comments
Post a Comment