Posts by Sergio • 133,294 points
2,786 posts
-
3
votes2
answers490
viewsA: Callbacks in Javascript
The concept of callback is more common in asynchronous cases. It is possible to say that impri is the callback, although the concept itself is most common in asynchronous processes, because it is…
-
9
votes2
answers58
viewsA: How can I create a regular expression that accepts a certain number at most once
With regex you can do it like this: const a = 'sskfdam09471928'; const b = 'asldk02210920139'; function validar(str) { return !!str.match(/^[^2]*2?[^2]*$/); } console.log(validar(a)); // true…
-
1
votes1
answer22
viewsA: Read meta with javascript
You can use document.querySelector to select DOM/page elements and extract what you are looking for. To read the example you have indicated you can do so: var apiKey =…
javascriptanswered Sergio 133,294 -
3
votes1
answer625
viewsA: Taking data from Xios and vuejs
You mustn’t use computed thus, the computed is ideal for synchronous logic and should be a pure function. Uses the watch to follow changes in turmas_checked and with imediate: true to run the…
-
0
votes1
answer64
viewsA: Multiple list Component calls
I imagine that modal can only open once, to avoid having N open dialogs. The solution I suggest is to have the component outside the loop and a v-if to open if there is an assigned ID in the object…
-
1
votes1
answer49
viewsA: Problem with Get, Set javascript
I’m not sure what you mean by "a Javascript MVC class", but the problems you have in your example are the method initialize runs before of your set, and therefore the console.log gives Undefined. If…
javascriptanswered Sergio 133,294 -
1
votes3
answers33
viewsA: Take the variable div’s attribute and send one at a time to another function
As has already been mentioned document.querySelectorAll("#lista div") returns a list, type array and you cannot fetch the Ids directly, you have to iterate. So you could do with less code the…
javascriptanswered Sergio 133,294 -
1
votes2
answers145
viewsA: Display message on screen from an object
You can create a function that consumes this type of objects and return the complete String. The ideal would be to have the gender in the object so you could dynamically change the uma for um.…
javascriptanswered Sergio 133,294 -
1
votes2
answers35
viewsA: When assigning an attribute to a function, is it like creating a variable within that function?
I don’t know where you read that idea but that’s not quite it, look at the example: function copaMundoA() { console.log(1, typeof pais, copaMundoA.pais); // undefined Ruússia } copaMundoA.pais =…
javascriptanswered Sergio 133,294 -
2
votes2
answers82
viewsA: How to access the data-weekday property of the div element with javascript?
You can use the .dataset: const weekDay = document.getElementById('weekday').dataset.weekday; console.log(weekDay); // 7 <div style="display: none;" id="weekday" data-weekday="7"></div>…
javascriptanswered Sergio 133,294 -
7
votes1
answer3056
viewsA: Grab button value in js
You’re mixing the code a little bit, it’s simpler: function clickTeclado(letra) { alert(letra); } <button class="teclado" id="qTeclado" onClick="clickTeclado(this.value);"…
javascriptanswered Sergio 133,294 -
2
votes1
answer144
viewsA: How to display an element from a true or false within the Object? Javascript Reactjs
You can use .filter to filter the state and then map to the JSX you need. Notice that in your States you have written Objects objetcs, I corrected in the example below class Componente extends…
-
3
votes1
answer143
viewsA: Objects with For/In
You can use Object.defineProperty() with enumerable: false,, and this will hide the property of iterators. function CarroAspects(modelo, chassi, qtdPortas) { this.modelo = modelo; this.chassi =…
javascriptanswered Sergio 133,294 -
1
votes1
answer288
viewsA: Check user Age using Jquery(datepicker) & JSP
Your logic is correct. I suggest you join changeYear: true, to the datepicker and add } and }); missing from your code, to close the onSelect, but also the object and method invoked in…
-
4
votes3
answers58
viewsA: Is it possible to use Jquery to animate Background-color?
You can (and should, for performance reasons) use CSS. That is by adding and removing classes. An example would be like this: setInterval(() => {…
-
1
votes2
answers74
viewsA: Update object values via GET without repetition
Use arrays to easily iterate and simplify code. In these cases it’s good to find patterns to simplify. An example would be: const periodicidade = ['mensal', 'trimestral', 'semestral', 'anual'];…
-
0
votes2
answers93
viewsA: Filter code elements
I suggest not doing this job with regex but creating elements with the Javascript API. It’s not clear on the question how you’re going to use/integrate this into Vue, but you can do something like…
-
0
votes1
answer849
viewsA: How to break lines using template string (ES6)?
If the idea is only to facilitate reading you can do: const url = ` backoffice/ usuarios/ ${this.id}/ grupo/ ${this.grupo}/ filial/ ${this.filial}/ multinivel/ ${this.multinivel} `; this .$http…
-
1
votes1
answer219
viewsA: Load select text into input
Place the script after HTML and you can do this with: $('#testID').change(function() { $('#vai').val(this.value); }); Example: <html> <head> <title>TESTE</title> <script…
javascriptanswered Sergio 133,294 -
0
votes2
answers53
viewsA: Scope of Literal Objects - Javascript
When you declare the object the value that is assigned to .context is this which is the context of implementation of that code, or is probably window. Which means the same thing you do: var foo =…
javascriptanswered Sergio 133,294 -
5
votes3
answers2286
viewsA: How to remove duplicate values from a multidimensional array in javascript?
The semantic method to be used is the .filter to filter the main array and the .some to check for copies. The advantage of using the .some is to be an iterator who stops when he finds a case that…
javascriptanswered Sergio 133,294 -
0
votes3
answers6975
viewsA: Javascript function 1 wait function return 2 (Sync await Promise.all)
The only thing you have to change is the last line, because result_final It’s a trial and you can use the then to consume the value it returns when the preset has completed the asynchronous part.…
-
0
votes2
answers127
viewsA: Combine alternative array with query array php/jquery
You can create an array where each question is an object with the format { pergunta: 'texto', alternativas: [ 'altern 1', 'altern x' ] } You can get it like this: $("body").on('click',…
-
1
votes1
answer60
viewsA: Adjacent JSX React syntax error
You have to return only 1 element in JSX. Vue.js also applies the same principle. React 16 changes a little, but you still have to encapsulate everything with <> or <React.fragment>,…
-
1
votes3
answers32
viewsA: Jquery . text printing only once
You have 3 errors in your code: to close the Divs with / lack the { in the opening of the function you must use ; and not , to separate the lines $(document).ready(function(){…
-
1
votes3
answers883
viewsA: Add columns Vue.js
You can simplify that and use the Math.maxthus: methods: { nota: function() { return Math.max(...arguments); } } so you don’t get stuck with only 2 values. You could still make a new array in…
-
3
votes1
answer706
viewsA: The `useMongoClient` option is no longer necessary in Mongoose 5.x, Please remove it
This was one of the changes from version 4 to 5, in the migration manual talk about it. Basically: from version 5 this option has been removed, the value is always true, so it is now a mistake to…
-
0
votes1
answer59
viewsA: How to send the value of a radio with the concatenated user id?
You can use the slice to extract only part of the ID string after the size of the suffix you have. An example would be: $('.btn-like').click(function() { var id_usuario = this.id.slice(9);…
-
4
votes2
answers1125
viewsA: Display default date field BR yyyymmdd to dd/mm/yyyy with javascript
You can treat this as a string, or convert to Date and show with country rules. treating as string: var formatoBr = '2020/05/10'.split('/').reverse().join('/'); console.log(formatoBr); // 10/05/2020…
-
2
votes1
answer493
viewsA: update with Vue.js
In the documentation of router-link the example that applies to your case is: <router-link :to="{ path: 'alterarProduto', params: { productID: 123 }}">User</router-link> so you can pass…
-
2
votes1
answer51
viewsA: Javascript programming
In steps: a) to receive input from the user and put in a variable: const nome = prompt('Escreva um nome!'); b) display text that has been inserted: alert(nome); Everything together in a role would…
javascriptanswered Sergio 133,294 -
0
votes2
answers191
viewsA: Ajax requests with the Fetch API keeps repeating
You can create a "memory" function that checks if values have changed before making a new request: const PostData = (function() { let A1_CGC, inicio, fim, body, lastBody; const config = { method:…
-
4
votes1
answer113
viewsA: Convert Camelcase strings to kebab-case
I think what you want is to convert strings into Camelcase for kebab-case, you can do it like this: function camelCaseToKebabCase(str) { return str.replace(/([a-zA-Z])(?=[A-Z])/g,…
-
0
votes1
answer540
viewsA: Uncaught Typeerror: Cannot read Property 'addeventlistener' of null
The problem you have is that when you run var button = document.getElementById("copy-button"); the button has not yet been added to the DOM, since the $(function(){}) jQuery’s run after, despite…
-
3
votes2
answers1925
viewsA: Concatenate string with Vue in href
You can use a reactive value (computed) for this, if you concatenate in the template he can not see cache and will calculate each render. Would that be: Template: <h3 class="item-title"><a…
-
1
votes2
answers130
viewsA: Get the selected item from iView’s Treeview
Note aside: I am active member iView. And I’m happy to help with related questions but I don’t always see them in time. You can use the @on-select-change to know which elements are selected when one…
-
4
votes4
answers2933
viewsA: Difference between operators && e ||
These operators are used in comparisons, the value on the right will be used: (case ||) when the boolean value of the comparator on the left false (case &&) when the boolean value of the…
-
1
votes1
answer99
viewsA: Access prop through Watchers in Vuejs
Gives a value default to that orders(I assume you’re the type array) and so when the value changes Vue, by reactivity will update the code that depends on it. So in time of props: ['orders'], uses…
-
2
votes1
answer441
viewsA: Problem when mapping api with Axios and React,
That method getAll calls a Praomise and the setState has to be called within of then to be chained in the asynchronous nature of that axios.get. So the code should be: .then(res => {…
-
5
votes3
answers1821
viewsA: Basic Doubt Javascript: How to change an object attribute?
You can do that with the .map as you mentioned. The code would look like this: const lista = [{ valor: "azul", tamanho: "grande" }, { valor: "verde", tamanho: "pequeno" }, { valor: "branco",…
javascriptanswered Sergio 133,294 -
3
votes1
answer31
viewsA: Is it possible to use addEventListner this way?
Yeah, the problem is you’re recording document.querySelector('#remover').addEventListener('click', before he existed. The best thing would be to join this event headphone when creating the button.…
-
0
votes1
answer57
viewsA: how to index an object numerically in Node.js?
To access with numeric index you must use arrays. And inside the array you can have objects. Something like that: const csvFile = ` animal, branco animal, preto inseto, branco inseto, preto animal,…
-
1
votes2
answers398
viewsA: Difficulty to remove item from inverted list in Vue
You have to use the index reversed also in the argument of that function like this: reverse.length - 1 - index Another way would be to pass the id and then do this.list = this.list.filter(obj =>…
-
1
votes2
answers564
viewsA: Consume Json Vuejs2 with Axios
I think what you’re looking for is two v-for. The first with v-for="(index, key) in product" where you extract Athos and Troad, and then the other v-for to iterate the array of each of these:…
-
4
votes1
answer1793
viewsA: Send values on onclick
You have to put quotes around $resp. What’s happening is that PHP compiles HTML like this: onclick='transfertoinput(this.id, RPG)' and then the this is interpreted as the element and RPG as a…
-
4
votes1
answer193
viewsA: Error in Document.getElementById() in Brackets
This warning is from the program that checks the syntax of the code, one of the most popular (and maybe what you have) is Eslint. This error should be ignored if this code is to run in the browser…
javascriptanswered Sergio 133,294 -
1
votes1
answer147
viewsA: Add data in a single Json
If everyone has the same files the thing is simple, just create a loop and use the loop index to extract the values. An example would be like this: const lojaA = [{ "id": 1, "nome": 'produto1',…
-
1
votes1
answer693
viewsA: Javascript - Decimals and Zeros on the left
I suggest separating in 3 steps: ensure that the number has 2 decimal places have a string of zeros with the maximum possible length to join to the absolute value in question join the signal +/- and…
javascriptanswered Sergio 133,294 -
2
votes3
answers707
viewsA: Foreach wait for the select result to proceed
You can use Promise and Promise.all to do that. The async library is excellent but it made more sense before the Promises were integrated into the language. So your code could be: function…
-
4
votes2
answers27
viewsA: Copying an image from one div to another - Jscript Methods
You can use target.appendChild(image.cloneNode()); where .cloneNode() is the method you seek to duplicate DOM elements. If you use .cloneNode(true) in elements that have progeny (which is not the…