简体   繁体   English

如何更改Aurelia中输入字段的可见性?

[英]How to change visibility of a input field in Aurelia?

I have following form in Aurelia. 我在奥雷利亚有以下表格。 In the top of the form, there's a drop down menu to select user type. 在表单的顶部,有一个下拉菜单可以选择用户类型。 There are only two options. 只有两个选择。 I need to show and hide some input fields when user change the type. 当用户更改类型时,我需要显示和隐藏一些输入字段。

IE : When user select type as 'Producer', I need to hide username. IE:当用户选择类型为“生产者”时,我需要隐藏用户名。 When user select 'Writer' , I need to show username and also hide email address. 当用户选择“作家”时,我需要显示用户名并隐藏电子邮件地址。 Like this. 像这样。 Need to do this using JavaScript controller. 需要使用JavaScript控制器执行此操作。

https://gist.github.com/chanakaDe/75934983cb4a02a7a8914959e38bf0f3 https://gist.github.com/chanakaDe/75934983cb4a02a7a8914959e38bf0f3

This is the HTML code as a github gist. 这是作为github要点的HTML代码。 Please give me a solution for this. 请给我一个解决方案。

You can use show.bind (if you just want to show and hide the element), or if.bind (if you want to add and remove it form the DOM). 您可以使用show.bind (如果你只是想显示和隐藏的元素),或if.bind (如果你想添加和删除其形成DOM)。 For instance: 例如:

<div class="form-group" id="div_username" if.bind="user_type === 'writer'">
  <label for="userame">Username:</label>
  <input type="text" class="form-control" id="userame" value.bind="userame" placeholder="Userame">
</div>

Runnable example https://gist.run/?id=33db6b8f919eb95d63b8bfbc2e912fe5 - Change the User Type to 'writer' and you'll see the Username input. 可运行的示例https://gist.run/?id=33db6b8f919eb95d63b8bfbc2e912fe5-将用户类型更改为“ writer”,您将看到Username输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM