React – TypeScript – Multi-dimensional Object – Need Support

I have an object like below with multi dimensional. In that I need to remove the particular section of array object only. Someone please help on this?

I need to remove this based on some condition. Please provide some suggestions on this.

Can we use single line array de-structuring option or any other solutions?

The only unique identifier here is “menuKey”: “sidebarRewards”

Needs to be removed part:

{
          "menuKey": "sidebarRewards",
          "label": "Smart Rewards",
          "iconSetName": "narrow",
          "description": "",
          "url": "example.com/account/sidebar/index.tmpl#rewards"
        }

Original Object:

{
  "profile-welcome": {
    "type": "user-profile-welcome",
    "params": {
      "welcomeBack": "Welcome Back!"
    }
  },
  "sidebar-tier": {
    "type": "user-sidebar-tier",
    "params": {
      "rewardsLink": {
        "label": "REWARDS",
        "url": "/smartrewards"
      }
    }
  },
  "account-links": {
    "type": "account-links",
    "params": {
      "menu": [
        {
          "menuKey": "sidebarAccount",
          "label": "My Account",
          "iconSetName": "narrow",
          "description": "",
          "url": "example.com/account/index.tmpl"
        },
        {
          "menuKey": "sidebarSettings",
          "label": "Account Settings",
          "iconSetName": "narrow",
          "description": "",
          "url": "example.com/account/profile_preferences.tmpl"
        },
        {
          "menuKey": "sidebarRewards",
          "label": "Smart Rewards",
          "iconSetName": "narrow",
          "description": "",
          "url": "example.com/account/sidebar/index.tmpl#rewards"
        },
        {
          "menuKey": "sidebarSignOut",
          "label": "Sign Out ",
          "iconSetName": "narrow",
          "description": "",
          "url": "example.com/account/signin.tmpl?_SUBMIT=signout"
        }
      ]
    }
  },
  "showcase": {
    "type": "showcase",
    "params": {
      "brandServices": {
        "header": "SKIN SERVICES",
        "infoLink": {
          "label": "",
          "url": ""
        },
        "list": [
          {
            "showCaseKey": "firstBrandShowcase",
            "title": "Skin Services.",
            "teaser": "Our team of Consultants is at your fingertips for tips and advice.",
            "label": "See All Skin Services",
            "url": "/services"
          },
          {
            "showCaseKey": "secondBrandShowcase",
            "title": "Try on makeup.",
            "teaser": "Find your perfect shades and use your phone to try them on.",
            "label": "Select Makeup to Try On",
            "url": "/clinicalreality"
          }
        ]
      }
    }
  }
}

php result into java script with query

im a newbie in object oriented programming so it would be ncie if someone can help me ^^

i got this js function rn:

function confirmDel(element) {
            let confirmDel = confirm("u sure u want to delete?");
                if (confirmDel) {
                    console.log(element);
                    window.location.href=="formprocess.php?firmadelete=";
                    alert(deleted");
                    }
                else{ 
                    alert("deleting canceled");
                    }
                }

and in my html i got

<a class="btn btn-outline-danger" href="formprocess.php?firmadelete=<?= $result['FirmenID']; ?>"><i class="fa-solid fa-trash-can"></i> </a></td>

maybe u see my try. I want to ask “U sure u want to delete?” and if im preesing “yes” it should bring me to the href "formprocess.php?firmadelete=<?= $result['FirmenID']; ?>"

how i can translate the $result[‘FirmenID’] into the js script?

Greetings from Germany
~Lampi

VPN Connect on Python

Can anyone help me connect directly to the VPN without launching the Windows interface?

I tried with this command in my views.py
(rasdial “vpnr1.proxad.net” + (username) + (password)”)
but it doesn’t work

make array of objects by key property

const val = { type: { id: '7455271e-0e5d-450b', key: 'INTERNAL_PERMANENT', }, status: { id: '87629ab0-1c04-436', key: 'ACTIVE', }, }, { type: { id: '7455271e-0e5d-450b', key: 'INTERNAL', }, status: { id: '87629ab0-1c04-4366', key: 'NOTACTIVE', }, },
**how to make a new array that has only object type **

result must be [
type: {
id: ‘7455271e-0e5d-450b’,
key: ‘INTERNAL_PERMANENT’,
},
type: {
id: ‘7455271e-0e5d-450b’,
key: ‘INTERNAL’,
},
]

Vue3 computed property changing its value inside onMounted hook

I have just been using and learning Vue for a week, and developing a small vue3 application using a CDN because that’s the requirement. I’m implementing using a composition api.
I have a computed property which is shown below.

...
const allCvlCount = computed (() => {
    return state.allCvls.length;
});
...

onMounted (() => {
    console.log(allCvlCount);
    console.log(allCvlCount.value);
})

When I try to print the object and its value property, they have different values as shown in the image below.

enter image description here

I tried to create a test case and its not behaving the same way as above. Where can I start debugging to pin down the cause of this discrepancy.

Here is my test case which is working fine.

<!DOCTYPE html>
<html>
<head>
<style>
#app {
  height: 400px;
}
</style>
</head>
<body>
<div id="app">
  <!-- <v-chart autoresize :option="myOptions"/> -->
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
<script>
    const { createApp, reactive, computed, onMounted } = Vue
    const app = createApp({
        setup() {
            const state = {
                myReactiveVar: [{'name': 'foo', 'count': 5}, {'name': 'bar', 'count': 3}, {'name': 'xyz', 'count': 8}]
            }
            const myComputedProperty = computed(() => {
                return state.myReactiveVar.filter(e => e.count <= 5).length;
            });

            onMounted(() => {
                console.log(myComputedProperty);
                console.log(myComputedProperty.value);
            });
            
            return {
                state,
                myComputedProperty
            };
        }
    })
    .mount("#app");
</script>
</body>
</html>

Why does using admin-ajax.php result in 20 GET requests all with status 200?

I have a private front-end dashboard that allows a user to manage their client information, documents, etc – essentially a CRM. On one particular page, the clients are all loaded onto the page on load, and then each client has additional information that is loaded via ajax to ensure I am not bogging the website down.

Now it all works just fine, but as the subject line mentions, I get 20 calls to admin-ajax.php when the function runs, and all return successfully. So I’d like to get this figured out while I am in development rather than it becoming a resource issue later on.

I am using the below function to handle the AJAX request, the scripts.js file below contains the script I’ve included lower down. Depending on which tab is clicked, I then load a specific template:

//prep the JS + Ajax
function cyber_load_scripts() {
    wp_enqueue_script('cyber_script', get_stylesheet_directory_uri() . '/js/scripts.js', array('jquery'), false, true );
    wp_localize_script('cyber_script', 'cyberAjax', array('ajaxurl' => admin_url('admin-ajax.php')));
}
add_action('wp_enqueue_scripts', 'cyber_load_scripts');

function ajax_load_tabs() {

$tab_id = $_REQUEST['id'];
$user_id = $_REQUEST['userid'];

if (str_contains($tab_id,'#onboarding')) {
    get_template_part( '/page-templates/dashboard/broker-dashboard', 'onboarding', array (
    'user_id' => $user_id,
    ));
}

elseif (str_contains($tab_id,'#tasks')) {
    get_template_part( '/page-templates/dashboard/broker-dashboard', 'tasks', array (
    'user_id' => $user_id,
    ));
}

elseif (str_contains($tab_id,'#incidents')) {
    get_template_part( '/page-templates/dashboard/broker-dashboard', 'incidents', array (
    'user_id' => $user_id,
    ));
}
                                                                    
die();

}
    
add_action('wp_ajax_ajax_load_tabs', 'ajax_load_tabs');
add_action('wp_ajax_nopriv_ajax_load_tabs', 'ajax_load_tabs');

And the script that initializes the ajax call when the client clicks on the tab. I skip the first tab as that is loaded with the page. I then pass the tab ID and the user ID to the AJAX request:

    $( ".tabContent" ).each(function(index) {
        $('.profileTabs ul li a').click(function(e) {
            
            e.preventDefault();
            
            //The first tab (overview) loads with the page
            if($(this).text().match('Overview')) {
                return false;
            }
            
            else {
                var tab_id = $(this).attr('href'); 
                var userid = $(this).attr('data-user');
    
                $.ajax({ 
                    url: cyberAjax.ajaxurl,
                    data: ({ 
                        action: 'ajax_load_tabs',
                        id: tab_id,
                        userid: userid,
                    }),
                    
                    success: function(data){
                              $(tab_id).html(data);
                    },
                    error: function(data)  
                    {  
                    //alert("Error!");
                    console.log("Error!");
                    return false;
                    }  
    
                }); 
            }    
        }); 

Any ideas how I can make this call only once as intended? See below screen shot for reference:

View of the XHR requests in the developers Network tab

How to Parse Array of JSON Objects using Axios

Using Axios I’m trying to pass JSON data as params to the endpoint URL.

My params:

const annotations = {
    "key": "Book.pdf",
    "pages": [
      {
        "start": "12",
        "end": "20"
      },
      {
        "start": "35",
        "end": "40"
      }
    ]
}

My async function:

try {
    const result = await axios.get(endpoint, {
        params: annotations,
        paramsSerializer: params => parseParams(params),
        headers: {
            'Authorization': 'Bearer ' + jwtToken,
            'Content-Type': 'application/json'
        },
        'withCredentials': true
    });
} catch (error) {
    console.log(error);
}

Function to parse the URL:

const parseParams = (params) => {
  const keys = Object.keys(params);
  let options = '';

  keys.forEach((key) => {
    const isParamTypeObject = typeof params[key] === 'object';
    const isParamTypeArray = isParamTypeObject && (params[key].length >= 0);

    if (!isParamTypeObject) {
      options += `${key}=${params[key]}&`;
    }

    if (isParamTypeObject && isParamTypeArray) {      
      params[key].forEach((element) => {
        options += `${key}=${element}&`;
      });
    }
  });

  return options ? options.slice(0, -1) : options;
};

The problem is that results in error 500:

https://api.mysite.com/ConvertBook?key=Book.pdf&regions=[object%20Object]&regions=[object%20Object]

I can’t find a solution on the web, so how can I parse Array of JSON Objects in Axios?

Checkboxs leading to a fetch call to produce data

As a user when I submit this form
I want a fetch call for each checkbox that is checked
So that I can load information from the API depending on what the selections are

<form id= 'selectionForm' action="#">
     <p>
        <label>
          <input type="checkbox" class="filled-in" name="Nexflix" id="Netflix" />
             <span>Netflix</span>
        </label>
      </p>
      <p>
         <label>
           <input type="checkbox" class="filled-in" name="Prime" id="Prime"/>
             <span>Amazon Prime Video</span>
         </label>
      </p> 
</form>

data-role=”tagsinput” working in crome and edge but not in Internet explorer

I am designing a site using Bootstrap. TagsInput is working in Chrome and Edge but not in Internet Explorer.
The tag boxes are not appearing in Internet Explorer
Attaching the code below:-

    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8" />
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
            <meta name="description" content="" />
            <meta name="author" content="" />
            <title>TNL metadata tagging</title>
            <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
            <link rel="stylesheet" type="text/css" href="css/bootstrap-tagsinput.css">
            <link href="css/styles.css" rel="stylesheet" />
        </head>
        <body>
            <div class="container">
              <form class="form-horizontal">
                <div class="row row-cols-1">
                  <div class="col mt-3"><b>Category</b></div>
                  <div class="col mt-3">
                    <div class="form-group">
                        <div class="col-sm-10">
                          <input class="form-control" id="focusedInput" type="text" value="News" data-role="tagsinput" />
                        </div>
                    </div>
                  </div>
                </div>
                <button type="submit" class="btn btn-primary">Submit</button>
              </form>
            </div>
            <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
      <!-- Latest compiled and minified JavaScript -->
    
    <script type="text/javascript" src="js/bootstrap-tagsinput.js"></script>
<script type="text/javascript">
$("input").val()
</script>
    </body>
    </html>

Screenshots:-
IE
Chrome

JS – On a callback, What’s the difference of using parenthesis and / or brackets on it?

I’m currently using react and I have noticed that the behaviour may change depending on how a callback is used. (Not sure if this is called notation). To illustrate my question, let’s use Array.map().

Array.map(el=> return el.name);
Array.map((el)=> return el.name);
Array.map((el)=> {return el.name});
Array.map(el=> {return el.name});

Are these four cases correct? What is the expected behaviour of each of them? Is there any that can be used “safely” always so it does bring up grammar errors?

Javascript Import Classes

I am trying to figure out how can we import classes in JavaScript, I found the following approach but it gives me an error on VS Code.

“SyntaxError: Cannot use import statement outside a module”

File 1:

import User from './User';
let user1 = new User("AB", "123456","01/01/2001");
console.log(user1.userName);
user1.setUserName = "CD";
console.log(user1.getUserName);

File 2:

export class User {

    constructor (userName, password, dob) {
        this.userName = userName;
        this.password = password;
        this.dob = dob;
    }
  
    get getUserName(){
        return this.userName;
    }
    set setUserName(newUserName){
        this.userName = newUserName;
    }
}

Adding new array to object without deleting the previous array

I have an array obj, and I am and Im adding another object links and I am creating a serie array in the object. I want to create another movie array after the serie array.

const obj = {
projectId: 0,
gridId: 0,
createValues: [
{
  field: "string",
  value: "string"
}
]
};

const dataCompo = {
"model-10389": 164703,
"model-10388": 164704,
"model-10387": 164705
};

const dataTraca = {
"model-10389": [1656, 1234, 1245],
"model-10384": [1656, 1234, 1245],
"model-10383": [1656, 1234, 1245],

};

const ser = Object.entries(dataCompo).map(([key, value]) => ({
modelId: key.substring(6),
id: value
}));
obj.links = {
        serie: ser
    };

const mov = Object.entries(dataTraca).map(([key,value]) => ({
modelId: key.substring(6),
ids: value
}));

obj.links = {
        movie: mov
    };

console.log(obj);

The thing is like this it is remplacing the whole links object and serie array with the movie one. I cannot quite figure how to use the spread operator.

I have managed to do it in one line like this :

    obj.links = { serie: ser, movie:mov };

However I would like to do it seperately just like above

Extracting values from a Javascript Object [duplicate]

I am trying o get data from SWAPI to integrate with another platform using javascript. I have some saved some links inside a variable while getting data.

a = {
  items: [
    { item: "https://swapi.dev/api/people/5/" },
    { item: "https://swapi.dev/api/people/68/" },
    { item: "https://swapi.dev/api/people/81/" },
  ],
};

From this code how do I extract the links only and save in a variable? I only need links. I tried object.values, object.keys() but couldn’t find a way. The platform I am using doesn’t support fetch() or $.each.

I am not quite sure how to get it done using for loop. Any assistance will be highly appreciated!