javascript - 在 angularjs 中创建一个可编辑的下拉菜单

标签 javascript jquery html angularjs combobox

我如何创建一个可编辑的下拉菜单,用户可以在其中添加一个新选项并填充它。

您可以在下面找到我的 html 下拉代码:

<select class="fieldDropdown" ng-model="currentFileGroup" title=""
 ng-options="value.ls_ItemValue as value.ls_ItemText for (key, value) in formLIST.filesGroup" 
data-style=""></select>

我希望当用户填写选项时,它会自动添加到数据库中。 使用 JavaScript、AngularJS 或 jQuery 都没有问题。

最佳答案

我通常使用 ui-select 进行此类交互: https://github.com/angular-ui/ui-select

在这种情况下,“标记”功能可能最接近您想要的功能: http://plnkr.co/edit/m1SQXUxftBLQtitng1f0?p=preview

<ui-select tagging="tagTransform" ng-model="person.selected" theme="bootstrap" ng-disabled="disabled" style="width: 800px;" title="Choose a person">
   <ui-select-match placeholder="Select person...">{{$select.selected.name}} &lt;{{$select.selected.email}}&gt;</ui-select-match>
   <ui-select-choices repeat="person in people | propsFilter: {name: $select.search, age: $select.search}">
      <div ng-if="person.isTag" ng-bind-html="person.name +' <small>(new)</small>'| highlight: $select.search"></div>
      <div ng-if="!person.isTag" ng-bind-html="person.name + person.isTag| highlight: $select.search"></div>
    <small>
     email: {{person.email}}
     age: <span ng-bind-html="''+person.age | highlight: $select.search"> </span>
    </small>
  </ui-select-choices>
</ui-select>
<p>Selected: {{person.selected}}</p>

关于javascript - 在 angularjs 中创建一个可编辑的下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24650059/

相关文章:

javascript - jQuery:是否可以在触发函数后停止单击或表单提交并恢复?

java - Java 的 Rhino 实现实现了哪个 JavaScript (ECMAScript) 版本(更新策略是什么?)

javascript - 使用 Ajax 帮助程序与使用常规 html 和 jQuery 代码

javascript - 这个网页的滚动效果是怎么实现的呢?

javascript - Django 中的电子邮件确认实现

javascript - Vue 组件内的 jquery

javascript - 使用 JS 单击时不显示表单

javascript - 寻找相当于 'onRender' 的 javascript 事件

javascript - 如何用js替换html中特定属性中的括号?

javascript - 使用 Tampermonkey 更改网站文本