i have html template div looks this:
<div id="some_{{model.property}}_{{other.value}}_text"></div>
i want use javascript in backbone view dynamically format injected values ids don't have spaces , slashes, etc. problem don't know right syntax grab them. right doing this:
var unformatted = "some_{{model.property}}_{{other.value}}_text"
and using jquery set id formatted value:
$('.common-class').attr('id', unformatted.formatme());
it is, of course, giving me literal string value curly brackets , path data. how can values instead? using backbone, marionette, require, bootstrap, , spring jsps on backend. lot!
@meagar correct. should create properties want before rendering template. template should reference new value , not original model property.
<div id="{{newvalue}}"></div>
if, example, want modify or change someproperty
rendered newvalue
, add newvalue
additional model property.
render: function() { this.model.set('newvalue', computenewvalue(someproperty)); this.$el.html(this.template(this.model.tojson())) }
if don't want newvalue
attribute polluting model, can add object passed template:
render: function() { this.$el.html(this.template( _(this.model.tojson()).extend({ newvalue: computenewvalue(someproperty) }) )); }
in latter case, model isn't modified, template able access computed value.