Backbone create a View

On this post just create a event and render it, and the event communicate with your html ID.

here is the code for your view, just put this in your body will work.

test on the browser should look like this.

backbone2

<script type=”text/template” id=”sample_template”>
<label>Name:</label>
<input type=”text” id=”name_desc”/>
<input type=”button” value=”Add Name” id=”btn”/>

</script>
<div id = “container”></div>
<script type=”text/javascript”>
Name = Backbone.View.extend({
el:$(‘#container’),
initialize:function(){
this.render();
},

render:function(){
var template = _.template($(‘#sample_template’).html(),{});

this.$el.html(template);

},
events:{
“click input[type=button]”: “addName”
},

addName:function(){
alert(“The name: “+$(‘#name_desc’).val() + ”  has been added”);
}
});

var name = new Name();
</script>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s