0

Just trying something but not sure how to do it.

Scenario:- I'm trying to render a page which have a configuration data and view data, so basically My template loop on the configuration data to render page and fetch value from view data to display.

so my model have something like

 model:{'confData':[{'displayName':'value1','fieldName':'Field1'},
                    {repeat similar object}
                   ],
        'viewData':{'Field1':'value1','Field2':'value2',....}
        }

Now in template I'm trying to render like:

{{#each confData}}
  this.displayName {{input type='text' value=viewData[this.fieldName] }}
{{/each}}

but it does not accept it. Any suggestion on how I can deal with this sort of problem.

PS: the confdata and view data in actual application will be api call which i can't change. I saw somthing like http://jsfiddle.net/GRaa5/4/ but when I tried changing as http://jsfiddle.net/weyzay5v/ it failed.

Thanks.

4
  • you can't use this inside templates... Commented Sep 22, 2014 at 10:16
  • @CodeJack but I did and it worked. here's the modified sample jsfiddle.net/n88g48rp Commented Sep 22, 2014 at 10:22
  • @CodeJack this definitely works in templates. It doesn't refer to the same thing as it does in JS though. In templates, it refers to the current context (which can be changed with block helpers). Commented Sep 22, 2014 at 11:18
  • ^ yep thats wat i meant.. Commented Sep 22, 2014 at 12:18

1 Answer 1

1

There is no way to do what you want purely with Handlebars. Remember that Handlebars templates are logic-less and for presentation only. My suggestion would be to make a computed property in your controller:

data: function() {
    var confData = this.get('confData');
    var viewData = this.get('viewData');

    return confData.map(function(data) {
        return {
            displayName: data.displayName,
            value: viewData[data.filedName]
        };
    });
}.property('confData.[]', 'viewData')

Then in your template:

{{#each data}}
    {{displayName}} {{input type='text' value=value}}
{{/each}}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.