简体   繁体   English

JqxCombo 值未从 ajax 结果设置 - Vue.js

[英]JqxCombo values not setting from ajax result - Vue.js

I have been trying to use JqxWidgets with Vue.js, the basic idea here is that we may have multiple ComboBox in the form and just calling the ComboBox template and providing the ajax call, it should get and set to that particular combobox.我一直在尝试将 JqxWidgets 与 Vue.js 一起使用,这里的基本思想是我们可能在表单中有多个 ComboBox 并且只需调用 ComboBox 模板并提供 ajax 调用,它应该获取并设置为那个特定的组合框。

So until now I have this所以直到现在我有这个

<template>
    <JqxComboBox ref="core_combobox" :width="`100%`" :height="25" 
                 @change="onChange($event)" :source="source" :selectedIndex="0" :displayMember="'label'" :valueMember="'value'">
    </JqxComboBox>
</template>

<script>
    import JqxComboBox from "./jqx-vue/vue_jqxcombobox.vue";

export default {
    components: {
        JqxComboBox
    },
    props : {
        comboDataSource : String
    },
    methods: {
        // Add here all used callbacks and/or events
        onChange: function (event) {
             if (event.args) {
                    let item = event.args.item;
                    if (item) {
                        alert(item.value)
                    }
                }
        },

        getComboSource : function (){
         axios
            .get('/admin/forms/'+this.comboDataSource+'/listDataSource')
            .then(function(response){
                console.log(response.data);
                return response.data;

                });


    },
    data: function () {
        return {
            regexPattern : /(?<=\()(.*)(?=)\)/g,
            datafields: [
                { name: 'value' },
                { name: 'label' }
            ],
            source: this.getComboSource()
        }
    }
}
</script>

Result of the axios is this for some reason is converted to vue instances like so, axios的结果是 this 出于某种原因被转换为 vue 实例,如下所示,

0: {__ob__: Observer}
1: {__ob__: Observer}
length: 2
__ob__: Observer {value: Array(2), dep: Dep, vmCount: 0}
__proto__: Array

The value inside 0 is 0里面的值是

label: "SS Sales Corportation"
value: 1
__ob__: Observer {value: {…}, dep: Dep, vmCount: 0}
get label: ƒ reactiveGetter()
set label: ƒ reactiveSetter(newVal)
get value: ƒ reactiveGetter()
set value: ƒ reactiveSetter(newVal)
__proto__: Object

If anyone is familiar with this, please I have two question.如果有人熟悉这个,请问我有两个问题。 1. Why is the return is not just js object? 1.为什么返回的不仅仅是js对象? 2. When the data comes, how can I set it to the JqxCombo ? 2.数据来了,怎么设置到JqxCombo

1st question :第一个问题

That's a special property added by Vue, it's part of the Reactivity system which allows Vue to track data changes and react to them, you could read more about it in the official doc这是 Vue 添加的一个特殊属性,它是 Reactivity 系统的一部分,它允许 Vue 跟踪数据更改并对其做出反应,您可以在官方文档中阅读更多信息

2nd question :第二个问题

When the data comes using axios call you could assign it to source property like :当数据使用axios调用时,您可以将其分配给source属性,例如:

getComboSource: function() {
  axios
    .get('/admin/forms/' + this.comboDataSource + '/listDataSource')
    .then(function(response) {
      console.log(response.data);
      this.source= response.data;//<-------

    });


}

and in your data Object you should initialize source as follows:在您的数据对象中,您应该按如下方式初始化source

data: function() {
  return {
    regexPattern: /(?<=\()(.*)(?=)\)/g,
    datafields: [{
        name: 'value'
      },
      {
        name: 'label'
      }
    ],
    source:{}//<----
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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