【问题标题】:ng2 select2 [data]. Not working if 'id' is different of 'text'ng2 select2 [数据]。如果“id”与“text”不同,则不起作用
【发布时间】:2017-09-26 17:46:59
【问题描述】:

我对 Angular 4 的 ng2 select2 插件有疑问。确实,如果我的 id 与我的文本不同,则插件错误并且在单击下拉值(值为“null”)后 select2 中没有显示任何内容。 ..

我只是复制了这个组件,(https://github.com/NejcZdovc/ng2-select2-demo/tree/master/src/app/demos/basic),我遇到了同样的问题......在初始化时,值显示得很好。但是当我更改输入的值时,选择不显示任何内容...... 请参阅下面的几个步骤来理解我的意思。

有人有解决这个错误的方法吗?谢谢

【问题讨论】:

  • 没人回答吗?
  • 大家好,我想用“idNumber”代替“id”和“textData”代替“text”,有人知道,我该怎么做?

标签: angular jquery-select2


【解决方案1】:

您可以通过以下代码获取id

console.log('changed value is '+event.data[0].id);

component.html

<select2 [data]="exampleData" [value]="startValue" [width]="150" (valueChanged)="handleChange($event)"></select2>

component.ts

handleChange(event):void {
   console.log('changed value is '+event.data[0].id);
}

函数参数中的事件变量包含如下值:

{  
   "value":"basic3",
   "data":[  
      {  
         "selected":true,
         "disabled":false,
         "text":"Basic 3",
         "id":"basic3",
         "element":{  

         }
      }
   ]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-01
    • 1970-01-01
    • 2019-06-16
    • 1970-01-01
    • 2015-10-12
    • 2018-10-12
    • 1970-01-01
    相关资源
    最近更新 更多