我一直在尝试将JqxWidgets与Vue.js结合使用,这里的基本思想是,我们可以在表单中使用多个combobox,只需调用ComboBox模板并提供ajax调用,它就应该得到并设置为特定的组合框。
所以直到现在我才有了这个
<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>axios的结果是由于某种原因被转换为vue实例,
0: {__ob__: Observer}
1: {__ob__: Observer}
length: 2
__ob__: Observer {value: Array(2), dep: Dep, vmCount: 0}
__proto__: Array0内的值是
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如果有人熟悉这个问题,我有两个问题。1.为什么返回不仅仅是js对象? 2.当数据出现时,我如何将其设置为JqxCombo?
发布于 2018-12-10 17:41:16
第一项问题:
这是Vue添加的一个特殊属性,它是Reactivity的一部分,它允许Vue跟踪数据更改并对其做出反应,您可以在官方医生中更多地了解它
第二个问题:
当数据使用axios调用时,可以将其分配给source属性,如下所示:
getComboSource: function() {
axios
.get('/admin/forms/' + this.comboDataSource + '/listDataSource')
.then(function(response) {
console.log(response.data);
this.source= response.data;//<-------
});
}在数据对象中,您应该初始化source,如下所示:
data: function() {
return {
regexPattern: /(?<=\()(.*)(?=)\)/g,
datafields: [{
name: 'value'
},
{
name: 'label'
}
],
source:{}//<----
}
}https://stackoverflow.com/questions/53710490
复制相似问题