javascript - BackboneJS : where to declare the function inside a view? -


i'm starting learn backbonejs. here code :

var todoitem = backbone.model.extend({});  var todoitem = new todoitem({     description: 'pick milk',     status: 'incomplete',     id: 1 });  var todoview = backbone.view.extend({     render: function()     {         var html = '<h3>' + this.model.get('description') + '</h3>';         $(this.el).html(html);     } });  var todoview = new todoview({ model: todoitem }); todoview.render(); console.log(todoview.el); 

but error :

uncaught typeerror: expecting function in instanceof check, got undefined     _.extend._setelement @ backbone.js:1233     _.extend.setelement @ backbone.js:1222     _.extend._ensureelement @ backbone.js:1302     backbone.view @ backbone.js:1170     child @ backbone.js:1831     (anonymous function) @ (index):28 

what doing wrongly ? don't understand need create function it's waiting for.

in backbone.js, _setelement used set this.$el , this.el. particular error happening on first line in following backbone.js code:

 _setelement: function(el) {    this.$el = el instanceof backbone.$ ? el : backbone.$(el);    this.el = this.$el[0];  }, 

as can see, checking if it's instanceof backbone.$, based on error backbone.$ null. this error indicating jquery either didn't load or isn't on page. make sure include jquery before include backbone on page.

here's example of needed requires using cdns host these libraries.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.1/backbone-min.js"></script> 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -