Set and access view bindings in handlebars

…衆ロ難τιáo~ 提交于 2019-12-13 04:31:17

问题


Is there a way to set a binding in handlebars for a view and then use that in the template?

{{view App.SKillView skillBinding="Skill1"}}

and then in the template use that binding such as:

<script type="text/x-handlebars" data-template-name="skill">
     <h5>{{skill}}</h5>
     <div {{action spendPoints skill 1}}></div>
</script>

The view class is really simple:

App.SkillView = Ember.View.extend({
    templateName:'skill',
    classNames: ['skill']
});

These seems really simple, but for the life of me I can't figure it out. Any help would be appreciated. I basically want to be able to dynamically reuse the same view through my App and have it affect different skills in each place. Thanks!


回答1:


You're pretty much there, you just need to access the properties via the view

<script type="text/x-handlebars" data-template-name="skill">
  <h5>{{view.skill}}</h5>
  <div {{action spendPoints view.skill 1}} href="#"></div>
</script>



回答2:


Have you tried adding attributeBindings: ['skill'] to your view?



来源:https://stackoverflow.com/questions/16574349/set-and-access-view-bindings-in-handlebars

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!