Vue implements HTML drop-down box using enumeration type

Source: Internet
Author: User

The drop-down box contains the value in option and the options used to display it, and the general background is to use the values instead of the options displayed in the foreground

First step: Write the enumeration type required by the drop-down box

Statusenum.java

 Public enum Statusenum {    RED,    YELLOW,    GREEN}

Step Two: Write the option to hold the value and display in the corresponding option in the drop-down box

Statusdto.java

 Public class statusdto {    private  String code;     Private String name;     // setter, Getter}

Step three: Write a controller (resource)

Statusresource. java

@Path ("/status") Public classstatusresource{@GET @Path ("/getstatus")     PublicList<statusdto>GetStatus () {List<StatusDTO> list =NewArraylist<statusdto>(); Statusdto Statusdto=NULL;  for(Statusenum status:StatusEnum.values ()) {Statusdto=Newstatusdto ();            Statusdto.setcode (Status.tostring ());        List.add (statusdto); }        returnlist; }}

Fourth step: Write JS file

varStatusmodel ={selectstatus:[]//Store drop-down box results}varSelectvue =NewVue ({el:' #selectStatus ',//binding the DOM, typically a bound divData:statusmodel//the model used in the label})varSelectstatusresource = Vue.resource ('/status/getstatus '). Get (). Then (function(response) {varStatuslist =Response.data; varList = []; varStatus =NULL;  for(vari = 0; i < statuslist.length; i++) {Status= Statuslist[i].code = = = ' RED '? ' Red ': statuslist[i].code = = ' YELLOW '? ' Yellow ': statuslist[i].code = = ' GREEN '? ' Green ': ';    List.push ({code:statuslist[i].code,name:status}); } statusmodel.selectstatus=list;});

Fifth step: Writing HTML files

 <DivID= "Selectstatus"style= "width:140px;height:37px;text-align:right;margin:0 2px;position:relative;float:left;">            <SelectID= "status"style= "Width:100%;background: #ddebff; Height:35px;color: #082451; border:1px solid #082451; border-radius:2px; font-size:12px;box-shadow:3px 3px 3px #96c0e7 inset; ">                <optionvalue= "-1">-Please select-</option>                <optionv-for= "option in Selectstatus": Value= "Option.code">{{Option.name}}</option>            </Select>        </Div>

Display effect:

Vue implements HTML drop-down box using enumeration type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.