0

I'm new at BackboneJS... I have a view, which is associated to a model. Now i have to show some additional data on that view, which is not part of associated model and it's not stored in database. I've been browsing through tutorials and examples on the web, but all of them are dealing with views that have all it's attributes inserted/read from database. I've been trying to set values directly with jQuery, but it's not working ... $('#textfield).val('some text');

It's probably a simple answer, but it seems that i'm running in circles. Some help would be appreciated.

cartoonle
  • 101
  • 1
  • 7
  • what exactlly you have to add? something static like picture, text, footer header or something dynamic, like other model or collection ? – Evgeniy Jul 01 '14 at 10:40

1 Answers1

0

Lets expect you have defined template in view like this

_.template($('#tpl').html()

And have simmilar code in template

<script type="text/template" id="tpl">
    <ul>
        <li> <%= someModelData %> </li>
        <li> <%= otherModelData %> </li>
    </ul>
</script>

To add something static you can just update this template

<script type="text/template" id="tpl">
    <div>
        <h1>Lets add title and wrap content in div</h1>
        <ul>
            <li> <%= someModelData %> </li>
            <li> <%= otherModelData %> </li>
        </ul>
    </div>
</script>

UPDATE:

If you need to pass some additional dynamic data to template you can follow the way described in this post

UPDATE 2:

In case you would like to update template partly you can use sub-view like

initialize: function(){
    this.statusView = new someViewInstance();

    this.on('some', this.onSomeEvent, this);
},

onSomeEvent: function(){
    var stHtml = this.statusView.render().el;
    this.$el.find('.status').html(stHtml)
}
Community
  • 1
  • 1
Evgeniy
  • 2,915
  • 3
  • 21
  • 35
  • well, i would like to do that in runtime, when some event is triggered... I need label (for example) with some kind of status message, which is showing what is happening in background. – cartoonle Jul 01 '14 at 11:09
  • then u'd better to use subChild and re-render this sub child on parent view event fire – Evgeniy Jul 01 '14 at 11:14