-
Notifications
You must be signed in to change notification settings - Fork 0
Helpers klee
sebez edited this page Nov 19, 2014
·
17 revisions
In the app/lib directory, there is a file url_helper.js, its role is to generate and parse urls calling the methods:
This function is use in order to build url from a rootname and a object you want to pass into the url as params.
var urlHelper = require('../lib/url_helper');
var url = urlHelper.generateUrl('rootName', {param1: "nom", param2: "nom2"});
//url = '#rootName/?param1=nom¶m2=nom2'
Allow the user to bind a model backbone to a html form, using data-name
attribute. It uses data-* html5 attribute, to match model property.
module.exports = Backbone.Model.extend({
defaults: {
id: undefined,
startDate: undefined,
endDate: undefined,
name: undefined,
}
});
This html form comes from a template which is a Handlebars.js template. The View Helper with the input_for method automatically add the data-name attribute to the generated html input. The data-name is use to automatically bind the form on the Backbone model.
<form>
<input name="inputName" data-name="id"/>
</form>
Require the helper when you need it:
var formHelper = require('../lib/form_helper');
In the view code, treating the sumbit event or a button event:
//
var data = {
inputs: $('input', this.$el),
options: $('option:selected', this.$el)
};
formHelper.formModelBinder(data, this.model);
//The model gets the property id fill by the form.