Associating a baseline view with html is already a renderer

Is there a fancy way to bind a view to html already on the page renderer?

Your server example loads the entire html page and then loads the views on top of that html without using the rendering method the first time the page loads.

+5
source share
3 answers

I did something similar to what I think you are trying to do. In my case, I added Backbone functionality over existing forms. Here is an example:

Existing HTML:

<div id="my-app">
  <form name="input" action="html_form_action.asp" method="get">
    Username: <input type="text" name="user" id="username" />
    <input type="submit" value="Submit" />
  </form> 
</div>

Backbone:

var MyFormView = Backbone.View.extend({
  events: {
    "submit form": "formHandler"
  },
  formHandler: function(evt) {
    evt.preventDefault();
    var nameVal = $('#username').val();
    this.$el.append('<p>hello: ' + nameVal + '</p>');
  }
});

$().ready(function(){
  var myForm = new MyFormView({el: "#my-app"});
});

The key passes the existing html as the "el" property when creating your view.

+10
source

, , html el. , el. el (, "" el), setElement . setElement $el .

+1

, , JSFiddle, Backbone Views - , .

, .

: http://jsfiddle.net/phillipkregg/tVmTM/71/

0
source

All Articles