title: Backbone.js set View attribute
body: <p>I'm kind of new to Backbone and I'm having trouble understanding how to set the attributes of a View. I'm using a view without a model.</p>
  
  <p>This is the View:</p>
  
  <pre><code>var OperationErrorView = Backbone.View.extend({
      attributes: {},
      render: function(){
          var html = "&lt;h3&gt;" + this.attributes.get("error") +"&lt;/h3&gt;";
          $(this.el).html(html);
      }
  })
  </code></pre>
  
  <p>Then later on:</p>
  
  <pre><code>if (errors.length &gt; 0){
      errors.forEach(function(error){
          // var errorView = new OperationErrorView({attributes: {"error": error} });          Doesn't work
          var errorView = new OperationErrorView();
          errorView.set({attributes: {"error": error}})
          errorView.render()
          $("#formAdd_errors").append(errorView.$el.html());
      });
  }
  </code></pre>
  
  <p>Which is the correct approach to do this? Right now it doesn't work: When I try the method that is not commented out, it gives me the error <code>TypeError: errorView.set is not a function</code>, if I try it the first way, it just doesn't call the render() function.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <pre><code>var OperationErrorView = Backbone.View.extend({
      attributes: {},
      initialize: function(attributes){
          this.attributes = attributes;
      },
      render: function(){
          var html = "&lt;h3&gt;" + this.attributes.get("error") +"&lt;/h3&gt;";
          console.log("html");
          $(this.el).html(html);
      }
  })
  
  if (errors.length &gt; 0){
          errors.forEach(function(error){
              console.log(error);
              var errorView = new OperationErrorView({"error": error});
              errorView.render()
              $("#formAdd_errors").append(errorView.$el.html());
          });
      }
  </code></pre>
  
  <p>I tried including this.render() in the initialize function. Doesn't work. Doesn't even call the render function. Why?</p>