Ember hbs中的硬编码选择项/条件

时间:2019-03-05 23:32:48

标签: templates ember.js conditional

我没有将记录绑定到数据列表,而是有一个硬编码的按钮列表。我想要的是将条件绑定到按钮,但不知道如何操作。当记录设置为所选项目但没有硬编码值时,我可以

<button class='task data ManagedList'>Agreement Type</button>

然后是条件

{{#if selectedItem}}{{editor/administration/edit-managed-list store=store}}

想要做到这一点,以便在单击硬编码的“协议类型”按钮时,如果条件selectedItem为true,则条件

2 个答案:

答案 0 :(得分:0)

我不是100%肯定我理解这个问题,但是我认为,如果我关注您,您可以执行以下操作……(我将ember-truth-helpers插件用于eq助手):

template.hbs:

<button {{action "selectItem" "foo"}}></button>

{{#if (eq selectedItem "foo") }}
  conditional content
{{/if}}

在component.js中,将属性设置为要与之匹配的值:

selectedItem: '',

actions: {
  selectItem(val) {
    this.set('selectedItem', val);
  }  
}

答案 1 :(得分:0)

What you want to do is basically toggle the selectedItem property which should return bool. If in the template you have {{#if selectedItem}} then go back to the component context and set the 1. Add the selectedItem property in the component. E.g. selectedItem: false 2. Add an action on the button: <button class='task data ManagedList' {{action "toggleSelectedItem"}}>Agreement Type</button> 3. On the component side under the actions hash toggle the property:

actions: {
    toggleSelectedItem() {
      this.toggleProperty('selectedItem');
    }
  }

This should toggle your selectedItem property between true and false.