嵌套每个以及​​是否使用Handlebars和EmberJS

时间:2022-10-18 19:15:39

I have two list of models which have relations.

我有两个有关系的模型列表。

A has many B

I loop through B with {{#each}} and generate a <table> with it and every row has a <select> where all As, that exist, are listed.

我使用{{#each}}遍历B并使用它生成

,并且每行都有一个

If an B belongs to an A it should be selected in the <select>

如果B属于A,则应在

Example:

例:

<table>
  {{#each b in listofb}}
    <tr><td>
      <select>
        {{#each a in listofa}}
          {{#if b belongsto a}}
            <option selected>a.someAttribute</option>
          {{else}}
            <option>a.someAttribute</option>
          {{/if}}
        {{/each}}
      </select>
    </td></tr>
  {{/each}}
</table>

There is probably a way to do this with handlebar-helpers, but I don't know if I can use their output later with Ember controller actions.

可能有一种方法可以用车把助手做到这一点,但我不知道我以后是否可以使用他们的输出与Ember控制器动作。

1 个解决方案

#1


1  

Use Ember.Select http://emberjs.com/api/classes/Ember.Select.html

使用Ember.Select http://emberjs.com/api/classes/Ember.Select.html

{{view 'select' value=someControllerProperty}}

It helps you keep logic inside the controller.

它可以帮助您将逻辑保留在控制器内。

Now, in the controller you can react upon changes to the value selected with:

现在,在控制器中,您可以对所选值的更改作出反应:

processValueChange: function() {
  // do stuff
}.property('someControllerProperty')

#1


1  

Use Ember.Select http://emberjs.com/api/classes/Ember.Select.html

使用Ember.Select http://emberjs.com/api/classes/Ember.Select.html

{{view 'select' value=someControllerProperty}}

It helps you keep logic inside the controller.

它可以帮助您将逻辑保留在控制器内。

Now, in the controller you can react upon changes to the value selected with:

现在,在控制器中,您可以对所选值的更改作出反应:

processValueChange: function() {
  // do stuff
}.property('someControllerProperty')