引导与2角多选GET值 [英] bootstrap multiselect get value with Angular 2

查看:177
本文介绍了引导与2角多选GET值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的多选下拉列表中选定的选项的值。
但我没有得到这个由 ngModel ..

I want to get the value of the selected options in my multiselect dropdown list. But i do not get this done by ngModel..

下面的HTML:

 <div class="col-xs-offset-1 col-xs-3">
    <form class="btn-group" id="select-form">
        <select id="dropdown-list" multiple="multiple" [(ngModel)]="selectedObject"></select>
       <button type="reset" id="reset-button" class="btn btn-default"><span class="glyphicon glyphicon-refresh"></span></button>
    </form>
</div>

和这里的for循环而追加选项选择:

and here the the for loop which append options to the select:

ngOnInit() {
    for(var i = 0; i < this.checks.length; i++){
        var append = this.checks[i];
        $('#dropdown-list').append('<option>'+ append.name +'</option>');
    }

这是因为 ngFor 不工作在这里..但是这不是我在这种情况下的问题。

This because the ngFor is not working here.. but that's not my question in this case.

有人可以帮我登录所选选项= [(ngModel)] =选择对象

Can somebody help me to log the selected options = [(ngModel)]="selectObject"

推荐答案

多重选择似乎并不能被支持,看到的 https://github.com/angular/angular/issues/4427

Multi-select does not seem to be supported yet, see https://github.com/angular/angular/issues/4427.

下面是一个解决方法(不使用查询选择器):

Here's a workaround (that does not use query selectors):

@Component({
  selector: 'my-app',
  template: `{{title}}<p>
  <select multiple="multiple" (change)="change($event.target.options)">
    <option *ngFor="#item of items">{{item}}</option>
  </select>
  <p>{{selectedOptions | json}}`
})
export class AppComponent {
  title = "Angular 2 beta - multi select list";
  items = 'one two three'.split(' ');
  constructor() { console.clear(); }
  change(options) {
    this.selectedOptions = Array.apply(null,options)  // convert to real array
      .filter(option => option.selected)
      .map(option => option.value)
  }
}

<大骨节病> Plunker

这篇关于引导与2角多选GET值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆