PrimeNG P-ListBox在选择时抛出错误

时间:2018-01-06 06:37:46

标签: angular primeng

从我的列表框模块中选择一个项目后,由于某种原因,该值仍然被作为对象而不是数组传入我的listbox.js,这是来自PrimeNG的p-listbox

HTML:

<p-listbox formControlName="programType" [options]="phoneTypeItems"  multiple="multiple" [style]="{'width':'350px'}" [listStyle]="{'max-height':'150px'}"
                     checkbox="checkbox" filter="filter">

                    </p-listbox>

.TS:

import { ListboxModule } from 'primeng/primeng';

export class SearchCareResultsComponent {

phoneTypeItems = [{ label: 'Mobile', value: '1' }, { label: 'Work', value: '2' }, { label: 'Home', value: '3' }]

}

这是错误:

  

Listbox.html:28 ERROR TypeError:this.value.concat不是函数       在Listbox.webpackJsonp ... / .. / .. / .. / primeng / components / listbox / listbox.js.Listbox.onCheckboxClick   (listbox.js:277)       在Object.eval [as handleEvent](Listbox.html:28)       at handleEvent(core.es5.js:12014)       at callWithDebugContext(core.es5.js:13475)       at Object.debugHandleEvent [as handleEvent](core.es5.js:13063)       at dispatchEvent(core.es5.js:8607)       在core.es5.js:9218       在HTMLDivElement。 (平台browser.es5.js:2651)       在ZoneDelegate.webpackJsonp ... / .. / .. / .. / zone.js / dist / zone.js.ZoneDelegate.invokeTask   (zone.js:425)       在Object.onInvokeTask(core.es5.js:3881)

UI和错误位置的图片: enter image description here

1 个答案:

答案 0 :(得分:0)

您使用的是哪个版本的PrimeNG?

也许可以尝试here中的文档。

尝试使用简单的城市对象,如果它适合你。

this.cities1 = [
            {label:'Select City', value:null},
            {label:'New York', value:{id:1, name: 'New York', code: 'NY'}},
            {label:'Rome', value:{id:2, name: 'Rome', code: 'RM'}},
            {label:'London', value:{id:3, name: 'London', code: 'LDN'}},
            {label:'Istanbul', value:{id:4, name: 'Istanbul', code: 'IST'}}
            {label:'Paris', value:{id:5, name: 'Paris', code: 'PRS'}}
        ];


<p-listbox [options]="cities" [(ngModel)]="selectedCities" filter="filter"></p-listbox>
相关问题