admin管理员组

文章数量:1415484

I am trying to set a value on the select box like below

  <dx-select-box
            [items]="reportingProject"
            id="ReportingProj"
            [text]="reportingProject"
            [readOnly]="true"
            >

And the reportingProject is in Component like

constructor(private psService: ProjectShipmentService, private pdComp: ProjectDetailsComponent) {
   debugger;
   this.reportingProject = this.pdComp.rProjectNumber;
   this.projectSalesOrder = this.pdComp.rSalesOrder;

Even though the reportingProject has data it doesnt show up in the page and the selectbox looks always empty

I am trying to set a value on the select box like below

  <dx-select-box
            [items]="reportingProject"
            id="ReportingProj"
            [text]="reportingProject"
            [readOnly]="true"
            >

And the reportingProject is in Component like

constructor(private psService: ProjectShipmentService, private pdComp: ProjectDetailsComponent) {
   debugger;
   this.reportingProject = this.pdComp.rProjectNumber;
   this.projectSalesOrder = this.pdComp.rSalesOrder;

Even though the reportingProject has data it doesnt show up in the page and the selectbox looks always empty

Share Improve this question asked Sep 27, 2019 at 5:29 trxtrx 2,16710 gold badges61 silver badges105 bronze badges 5
  • Is dx-select-box custom made input? Or is that a package ponent? – MonkeyScript Commented Sep 27, 2019 at 5:31
  • @Arcteezy It is from js.devexpress./Demos/WidgetsGallery/Demo/SelectBox/Overview/… – trx Commented Sep 27, 2019 at 5:32
  • Did you miss the closing tag i.e. </dx-select-box> – MonkeyScript Commented Sep 27, 2019 at 5:34
  • 1 what does your this.pdComp.rProjectNumber returns? it should return an array – jitender Commented Sep 27, 2019 at 5:36
  • @trx reportingProject must be a array or array of object – Yash Rami Commented Sep 27, 2019 at 5:37
Add a ment  | 

2 Answers 2

Reset to default 3

you can try like this

<dx-select-box id="myId" [items]="reportingProject" placeholder="my placeholder" [searchEnabled]="true" [(value)]="valueData" displayExpr="text" valueExpr="value" (onValueChanged)="onValueChange($event)">
</dx-select-box>

// items: must be a array or array of object 
// displayExpr: key of array of object which you would like to show on your selectbox
// valueExpr: value of your selectbox 

As mentioned in the Example of devexpress:

<dx-select-box
    [items]="simpleProducts"
    placeholder="Choose Product"
    [showClearButton]="true"
></dx-select-box>

where simpleProducts is an array of strings:

let simpleProducts: string[] = [
    "HD Video Player",
    "SuperHD Video Player",
    "SuperPlasma 50",
    "SuperLED 50",
    "SuperLED 42",
    "SuperLCD 55",
    "SuperLCD 42",
    "SuperPlasma 65",
    "SuperLCD 70",
    "Projector Plus",
    "Projector PlusHT",
    "ExcelRemote IR",
    "ExcelRemote BT",
    "ExcelRemote IP"
];

So you have to bind items to an array e.g.:

this.reportingProject = [this.pdComp.rProjectNumber];

本文标签: javascriptSetting the value on the SelectBoxStack Overflow