简体   繁体   中英

How to translate enum values?

I'm working on Node.js. In material.js model I have the following enum

var CONDITIONS = {
    FULLYWORKING: 'FULLY_WORKING',
    DETERIORATED: 'DETERIORATED',
    INREPAIR: 'IN_REPAIR',
    DEFECTIVE: 'DEFECTIVE',
};

I use it to show it in a form with Vue.js.

select#condition.form-control(name='condition', required, v-model='materialEdit.condition')

option(v-for='item,key in conditions' :value='key') {{item}}

The thing is I would like to have to option the translate the values to another language. I'm currently using i18n to translate the website. Any help is appreciated. Thank you.

You cannot iterate over an object like that. Normally you would call an enum like this:

var conditions = [FULLYWORKING, DETERIORATED, INREPAIR, DEFECTIVE]
option(v-for='(item,key) in conditions' :value='key') {{CONDITIONS.item}}

Another options is to use Object.keys(CONDITIONS) like this:

option(v-for='(item,key) in Object.keys(CONDITIONS)' :value='key') {{CONDITIONS.item}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM