Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Live binding issue no 3 (update on no2)

$
0
0
Been experimenting and made a little progress.

Latest status is the following template :

            <ul>
    {{#each this}}
        {{#if isSection}}
                <li>{{sectionName}}
                    <ul>
            {{#renderSection}}
                {{#each this}}
                    {{#if isQuestion}}
                        <li>{{question}}</li>
                    {{/if}}
                    {{#if isComment}}
                        <li>{{comment}}</li>
                    {{/if}}
                {{/each}}
            {{/renderSection}}
                    </ul>
                </li>
        {{/if}}
    {{/each}}
            </ul>

raw data is a simple array containing three types of object - Section, Question and Comment and from this an Observe.List is created and passed to the template.

The difficulty is that a section will contain multiple questions/comments so it seems impossible to have a simple template to render this without a helper - hence the 'renderSection' helper which is as follows :

         Mustache.registerHelper('renderSection', function(options) {
                // return all questions/comments in a given section
                var sectionNumber = this.sectionNumber;
                var data =_.filter(observableList, function(o) {
                      return o.sectionNumber===sectionNumber && !o.isSection;
                 });
                 return options.fn(data);
            });

The template renders just as expected.

Live binding works for :
      all updates of data in the observable
      additions and deletions of sections - observableList.push()/ .splice() etc

Significant that the rendering of sections doesn't depend on the helper ?

Live binding FAILS for :
      all additions and deletions of questions or sections

It's as though the helper is not being triggered on push/splice etc

Ron Yuen






Viewing all articles
Browse latest Browse all 3491

Trending Articles