Issues encountered when trying to set JqxCombo values from an ajax response within a Vue.js environment

I've been experimenting with integrating JqxWidgets into Vue.js. The concept is to have multiple ComboBox elements in a form and simply call the ComboBox template while providing an ajax call to get and set data for that specific combobox.

So far, this is what I have:

<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: {
        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>

The axios response seems to be converted to vue instances:

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

The value inside index 0 includes:

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 has experience with this issue, I have two questions: 1. Why isn't the return just a plain JavaScript object? 2. When the data is received, how can I properly set it to the JqxCombo?

Answer №1

Question one :

This unique feature is a special attribute implemented by Vue within its Reactivity system. This functionality enables Vue to monitor data alterations and respond accordingly. For more information, you can refer to the official documentation.

Question two :

When retrieving data using an axios call, you can assign it to the source property in this manner:

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

    });


}

In your data Object, ensure that you initialize the source property as shown below:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular fails to display the $scope

When I attempt to display a variable from my controller, the output shows as {{UserCtrl.user}} instead of the actual content stored in UserCtrl.user. My file structure is as follows: index.html scripts/app.js Below is the code snippet from index.html: ...

Sending dynamic data from JavaScript using AJAX to interact with PHP is a crucial aspect of modern

I recently created a script for file uploading that includes a progress bar. After making some modifications to add additional checks, everything seems to be working perfectly. However, I am currently facing an issue with passing a variable from the JavaSc ...

What is the best way to send data from a header component to a separate container component?

Utilizing React-router-dom, I am able to seamlessly switch between components in the following setup: <Router> <div> <Header /> <NavigationBar /> <Switch> <Route exact path ...

Sending a php DateTime object to javascript using Ajax

I sent a php datetime object via ajax. Now, I am able to access it in javascript like this: {"timezone":{"name":"Asia\/Tokyo","location":{"country_code":"JP","latitude":35.65231,"longitude":139.74232,"comments":""}},"offset":32400,"timestamp":147265 ...

Retrieving JSON formatted data from PHP using jQuery

If I use a $.post method in jQuery, how can I retrieve the response from PHP? $.post("sql/customer_save.php",{ what: "edit",customer_no: $customer_no}); I want PHP to send back a response. echo json_encode(array("customer_id"=>$customer_id,"customer_ ...

Design an HTML form that includes checkboxes for selecting multiple values

I am encountering an issue with a Checkbox field in an HTML input form. The values for the checkboxes are being fetched from another table and I am trying to select multiple users using these checkboxes. However, it seems like my code is not working as int ...

Tips for displaying multiple XML datasets on an HTML webpage

I came across an example on W3schools that I'm trying to replicate: http://www.w3schools.com/xml/tryit.asp?filename=tryxml_app_first However, the example only displays one CD. My goal is to showcase all the data (in this case CDs) in the XML file. H ...

Most efficient method to upload numerous images without any lag

I have a website where images are loaded only when they are slightly below the viewport. This method allows the site to load initially without images and then determine which ones need to be loaded based on the user's viewpoint. When a user scrolls ...

Send users from the web (using JavaScript) to the Windows Phone app, and if the app is not installed, direct them

In the following code snippet, I am using angular.js to detect the mobile platform and redirect to the native app. If the app is not installed, it will redirect to the market: $scope.isMobile = { Android: function() { return navigator.userAgent.ma ...

JQuery UI - Initial Load Error

Here is the script I am working with (paraphrased but in the same order): <script type="text/javascript" src="jquery-1.4.4.min.js"></script> <script type="text/javascript" src="jquery-ui-1.8.9.custom.min.js"></script> <script ty ...

Exploring the controller logic in Sails.js index.ejs

I'm struggling to understand how to integrate dynamic logic into the homepage of my Sails.js application. Currently, the homepage is static, but I want to display data on the index.ejs page. I have a MainController with an index function that retrieve ...

What is the process for producing multiple objects in JSON format and then accessing them from within <g:javascript> in Grails?

My goal is to add two select boxes within the results div using Ajax. I have a function named ajaxFun that retrieves values for the select boxes. However, I am struggling with rendering multiple objects as JSON and then retrieving them in my JavaScript fun ...

Create a datastring using a JSON object

When receiving data in JSON format from an AJAX call, the following code is used to parse it: var parsed=JSON.parse(data); An example output could look like this: {"confirm_type":"contract_action","job_id":12,"id":7} To generate a dynamic data string f ...

Unable to fetch information from Grid to a new window with Form in Extjs 4

Having trouble transferring data from a grid to a form in Extjs 4. I'm attempting to pass the field vid to the form for testing purposes, but I'm unable to do so. Despite trying several examples and ideas, I can't seem to make it work. The ...

Error: The react render method is unable to determine the length of an undefined property

I created this component to extract the length of the followers array in order to display the number of followers each user has on their profile. The fetchUser() function is used to call a backend API, and I implemented Redux and Reselect for state managem ...

Is there a way to remove the row after hitting its corresponding button?

Having trouble working with table tags in a cshtml page, particularly when appending tr and td elements using ajax. I'm unsure of how to delete a row when it's clicked on and also how to retrieve the values of inputs within each row. /// <r ...

Learn the art of merging forms with React Js! [Code snippet included]

I am currently working on building a form in reactjs inspired by the JSON Format at . index.js: import React, { useState, Fragment } from 'react'; import BasicDetails from '../components/basic_details'; import EmploymentDetails from &a ...

Attempting to remove the address bar while utilizing ChocolateChip-UI

After utilizing ChocolateChip-UI for a few days, I am impressed with how it aligns with established mobile standards. However, I encountered an issue while adapting my site to CC-UI - the address bar wouldn't disappear on scrolling despite trying var ...

What is the functionality of the reduce() higher-order function?

Here is the reduce() function implementation: function reduce(array, combine, start) { let current = start; for (let element of array) { current = combine(current, element); } return current; } Now, I am tackling this question: ...

Issues encountered with certain Tailwind styles functioning improperly when deployed in a production environment with Next.js

It seems that there are some style issues occurring in the production build hosted on Netlify for a specific component. The problematic component is a wrapper located at ./layout/FormLayout.tsx. Below is the code for this wrapper: const FormLayout: React.F ...