BackboneJS : where to declare the function inside a view?

后端 未结 1 1347
离开以前
离开以前 2021-01-26 08:10

I\'m starting to learn BackboneJS. Here is my code :

var TodoItem = Backbone.Model.extend({});

var todoItem = new TodoItem({
    description: \'Pick up milk\',
         


        
相关标签:
1条回答
  • 2021-01-26 08:28

    In backbone.js, _setElement is used to set the this.$el and this.el. Your particular error is happening on the first line in the following Backbone.js code:

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

    As you can see, we are checking if it's an instanceof Backbone.$, but based on your error Backbone.$ is null. This error is indicating that jQuery either didn't load or isn't on the page. Make sure you include jQuery before you include Backbone on your page.

    Here's an example of the needed requires using some CDNs that 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>
    
    0 讨论(0)
提交回复
热议问题