簡體   English   中英

Vue.js Multiselect中的數據

[英]Data in Vue.js Multiselect

我在Mounted axios調用中從服務器返回了一些響應數據,這很棒。

我正在尋找在multiselect:options中將某個部分用作選擇選項

Vue看起來像這樣

 // ===Component name
    name: "create_order",
    // ===Props passed to component
    props: {},
    // ===Components used by this component
    components: {
        Datepicker,
        Multiselect,
    },
    // ====component Data properties
    data(){
        return{
            formcreateorder: {},

            dateoforder: "",
            format: 'dd MMMM yyyy',

            orderconsultant: null,
            orderconsultantoptions: ['Mr', 'Mrs', 'Miss', 'Ms'],

            ordertype: null,
            ordertypeoptions: ['Temp', 'Perm'],

            orderclient: null,
            orderclientoptions: []

        }
    },
    // ===Code to be executed when Component is mounted
    mounted() {
        // Make a ajax request to get data from jobs route
        axios.get('clients/get').then(response => this.orderclientoptions = response.data);


    },
    // ===Computed properties for the component
    computed: {},
    // ===Component methods
    methods: {
    }

我的前端看起來

       <multiselect v-model="orderclient" id="orderclient" name="orderclient" :options="orderclientoptions"></multiselect>

我的回應是

{id: 1, clientname: "Tech Dojo", industry: "Tech", consultant: "Bob", clientstatus: "Lapsed",…}

我要做的就是在響應中使用客戶端名稱作為多選

我嘗試了幾種方法,但無法解決問題,我希望您能提供幫助

如果只關心客戶端名稱,則將結果從響應映射到具有客戶端名稱的字符串數組。 我假設您收到了很多客戶

mounted() {
    axios.get('clients/get')
         .then(response => 
               this.orderclientoptions = response.data.map(x => x.clientName);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM