Posts by BrTkCa • 11,094 points
375 posts
-
1
votes2
answers65
viewsA: Display script variable value in HTML
You can create an HTML element via Javascript and add the number in the created element. Example: function rollDice() { let roll = Math.floor(Math.random() * 100) + 1; console.log(`Rolled:…
-
2
votes1
answer360
viewsA: Send Formdata with Fetch API
You will need some middleware to process Multipart/formdata in the route of the nodejs. Multer is the most used option: https://github.com/expressjs/multer In the doc itself there are several…
-
2
votes1
answer94
viewsA: How to do Mongo inserts?
Mongodb does not have a type of auto-increment as in SQL databases, but _id is something very special to him. What you can do is indicate which is the _id manually:…
-
2
votes1
answer64
viewsA: The updateOne function is not working, returns me OK, but does not change anything
He may not be finding the document due to searching for _id be objectid, then you can do the following: const {ObjectId} = require('mongodb'); [...] updateOne({_id: new ObjectId(obj._id)}…
-
1
votes2
answers708
viewsA: How to manipulate DIV with Angularjs
You can use ng-show and display or hide elements when a flag is enabled. Example: angular.module('teste', []).controller('ctrl', function($scope) { $scope.conteudo1 = false; $scope.conteudo2 =…
-
2
votes1
answer19
viewsA: Charging more doesn’t work properly
You are sending the property data in jQuery’s Ajax with a method GET. Like the end-point is a post, change to type: 'POST'.
-
1
votes1
answer30
viewsA: How do I publish all git branchs at once to my remote repository on github?
The ideal is to enter each branch to know what is being sent, but the simplest way is: git push --all --all Push all branchs (i.e. refs over refs/heads/); cannot be used with another <refspec>…
-
1
votes1
answer74
viewsA: Handle Json Format Action Return
You can render the table body with the contents, something like that: function atualizaCampos(Eqpto, usuario) { var url = "@Url.Action(" ListaAcessoUsuario ", " Acesso ")"; $.post(url, { codEqpto:…
-
5
votes3
answers582
viewsA: How to remove spaces before and after a string without the Javascript "Trim()" method
You can use the regex: /^\s+|\s+$ Where: ^ identifies the beginning of the text \s identifies spaces | or $ end of text Example function fazerTrim(string) { return string.replace(/^\s+|\s+$/g, "");…
-
2
votes1
answer774
viewsA: Error changing state checkbox in Reactjs
You need to indicate what the context is for changeState(), so he says that this is undefined. Solution onChange={this.changeState.bind(this)} The bind(this) is passing the Component Checkbox to the…
-
0
votes3
answers378
viewsA: Get Mongo field value as Variable?
The findOne is an asynchronous instruction, so the correct way to access the result of the query is in callback, thus: Orders.findOne({name : 'Day'}, function(err, day){ if (!err){ let teste = day;…
-
1
votes1
answer245
viewsA: How to edit an attribute in the database?
If I understood your code, after the user search you can edit the property and save the document again: User.findOne({ name: decoded.name }, function(err, user) { user.active = false;…
-
1
votes1
answer1339
viewsA: How to relate two "models" to Mongoosis?
The closest Mongodb can come to relational banking is the use of Reference, where it is possible to create reference between documents. In case I want every USER to have a related ACTIONS Mongodb is…
-
4
votes1
answer2437
viewsA: The git push command is not working after removing a commit
This is because the HEAD of the local repository is behind the remote, this means that the git will not let you upload the new content without you making it clear that this is what you want.…
-
1
votes1
answer584
viewsA: How to add values by category?
For this type of operation it is necessary to group together with $unwind (deconstruct), which will deconstruct the array. I’ll explain. db.teste.aggregate([ {$unwind: "$filmes"} ]) It will give the…
-
2
votes2
answers210
viewsA: Format date with javascript
It is possible to pass the locale when using the function toLocaleDateString(): let data = new Date(); console.log(data.toLocaleDateString('pt-BR'));…
-
3
votes4
answers7563
viewsA: How to include and manipulate local JSON file?
With pure javascript you can read using Xmlhttprequest (yes, to read JSON). First create a file .json to use one of the functions. Example: var xmlhttp = new XMLHttpRequest(); var url =…
-
1
votes1
answer39
viewsA: Search Object Array value
Attribute the value of option: jsonOptions.forEach(function(item) { var option = document.createElement('option'); option.text = item.description; option.value = item.product;…
-
1
votes3
answers430
viewsA: Assign return of findOne to a global variable Node Node.js
findOne returns a Promise, so the result will only be ready when it is solved. The result can be used in this way: db.collection('configuracoes').findOne({ parametro: "pedido_num"}, function(err,…
-
3
votes3
answers96
viewsA: How to hide a text being bigger than my Div
You can put ... at the end of the text using text-overflow: ellipsis;. Example: div { width: 150px; height: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } <div> Lorem…
-
3
votes3
answers5001
viewsA: Hover effect on JS
A different option for the problem is to make this effect direct with CSS using some selectors, that may be: .classe ~ .outraClasse {} #se outraClasse é irmao de classe .classe + .outraClasse {} #se…
-
2
votes1
answer1642
viewsA: Fetch vs Xmlhttprequest vs Jquery Ajax
To fetch API in fact it is JS Vanilla because it does not belong to some third-party library as functions of jQuery and intends to solve some problems of Xmlhttprequest (XHR), which reigned for more…
javascriptanswered BrTkCa 11,094 -
0
votes1
answer421
viewsA: Callback as return of argument
That one question covers much about the concept of callback. The difference to what you scored is that you can pass the callback as a function parameter when the return function needs additional…
-
1
votes1
answer487
viewsA: Form with Node/EJS does not work!
bodyParser can’t stand it multipart/form-data, an alternative may be to use the ladies. Example: var express = require('express') var multer = require('multer') var upload = multer({ dest:…
-
1
votes1
answer560
viewsA: Date format error with input date
Probably at some point the field model is changed to another type that is not Date, that means that all <input type="date" > requires a Date. I believe the moment this happens is in the…
-
0
votes2
answers367
viewsA: Array declaration in javascript
The error is that there is no array cars. You can create it that way: let cars = new Array({ a: "Saab", b: "Volvo", c: "BMW" }); console.log(cars);…
-
1
votes1
answer834
viewsA: How to deploy a vuejs (Browserify) application to Heroku?
How are you using the http-server as a server, one option is to run npm-run-all in the start and to host on Heroku omit the host. With these changes the app will be interpreted: { "name": "teste",…
-
0
votes1
answer730
viewsA: URL has been identified as malicious and/or abusive Facebook API
You can open a request in the Facebook area Developers, as it is the only way to understand and try to remove the domain of the radar from them. But a quick solution is to change the URL used in the…
facebook-sdkanswered BrTkCa 11,094 -
10
votes2
answers2961
viewsA: Generate array with random values in Javascript
You can use the MDN function Math. to generate random numbers with interval: Math.floor(Math.random() * (max - min + 1)) + min; Example function getRandom(min, max) { return Math.floor(Math.random()…
javascriptanswered BrTkCa 11,094 -
0
votes1
answer86
viewsA: Function loading problem Node socket.io
Untested but you can try to connect outside the get, something like that: module.exports = function(app) { let io = app.get('io'); io.on("connection", function(ret) { let socket = ret; });…
-
0
votes2
answers62
viewsA: How to perform a function N times in 1 second
To reach 1 second you need to pass the milliseconds, which is equal to 1000. async function sendImage(i) { console.log('teste ' + Math.random()); } function sleep(ms) { return new Promise(resolve…
javascriptanswered BrTkCa 11,094 -
1
votes1
answer75
viewsA: Distinct and group in Mongodb
You can only group by codigoUrl that will keep only one document: db.getCollection('lojasDisponiveis').aggregate([{ $group: { _id: "$codigoUrl", codigoUrl: { $first: "$codigoUrl" }, codigosLojas: {…
-
1
votes1
answer118
viewsA: How to reverse the $unwind operation on Mongodb 3.4?
Using $group with $push will regroup the array to the object, thus: db.produtos.aggregate([{ $unwind: "$cores" }, { "$group": { "_id": "$_id", "cores": { $push: "$cores" } } } ])…
-
0
votes2
answers608
viewsA: Pause counting - setInterval
The syntax of clearInterval is: scope.clearInterval(intervalID) The repeating action identifier you want to cancel. This ID was returned by the call corresponding to the setInterval() As an example,…
-
1
votes1
answer97
viewsA: How is the conversion from String to Float done in Javascript Core?
The function responsible for making the conversion is the parseFloat and is not associated with any object. Number.parseFloat is the same used by parseFloat. To ECMA determines how the algorithm…
-
4
votes2
answers775
viewsA: Enable select option with javascript/jquery
If you are using jQuery, you can control by it more easily. Your javascript would look like this: // verifica se o input checked foi clicado $("input[name^='sofa']").on('click', function() { //…
-
6
votes2
answers3051
viewsA: Open link in a new tab without target or window.open
With window.location will not be possible because it references only the same page. You can create a dynamic link in the return of ajax with target=_blank and click on it: vm.pagarUpload =…
-
-1
votes5
answers335
viewsA: How to know the dynamically created textbox id?
One option is to listen to events in the document, that way: document.addEventListener('keydown',function(e){ // se o id do target contem op prefixo txtOutrosNomes if(e.target &&…
javascriptanswered BrTkCa 11,094 -
3
votes5
answers1019
viewsA: Get piece of text inside a javascript word
match will return the combined text, so you could change your code in this way that will check if it is different from null: let url = "João"; if (url.match("Jo")) { console.log("Match"); } It is…
javascriptanswered BrTkCa 11,094 -
1
votes3
answers94
viewsA: Because with Arrow functions the context is different from a common function?
The this lexicon in Arrow Function is very useful when working object-oriented in javascript (with classes for example). The MDN example is very practical: function Pessoa(){ this.idade = 0;…
javascriptanswered BrTkCa 11,094 -
1
votes1
answer132
viewsA: Error: Most Middleware in app nodejs
The error message says it all, the middleware is no longer native available on express and should be installed separately. I believe you are indicating due to the logger usage here…
-
1
votes1
answer44
viewsA: Gulp Watch JS infinite loop
The problem may be because you are applying the watch in all the js, where it fires if any of them change. Try applying this way: gulp.watch(['lib/*.js', '!lib/bundle.js'], ['build-js']);…
-
0
votes2
answers101
viewsA: How to mark options in ajax return?
You can go through the options and mark what exists on array: let array = [4, 5, 3, 7]; $("option").each((idx, item) => { array.indexOf(Number(item.value)) > -1 ? item.selected = true :…
-
0
votes3
answers49
viewsA: Capture input value (Only numeric fields) and put in Div
If you’re testing by the button you don’t need the on input. And to capture only the numbers can use: match(/\d+/g) Example $("#testar").click(function() { let valor =…
-
1
votes2
answers1429
viewsA: Exclude an element from a specific div
You need to get first to div and then get the kids targets, something like that: $("#lista").find("p").remove(); <script…
-
6
votes1
answer963
viewsA: Sort Array in Javascript
You need to pass the comparison function: var a = [20, 18, 10, 8, 6, 4, 2, 0] a.sort( (a,b) => a - b ); console.log(a); The reason for this is: If function according to its conversion to text and…
javascriptanswered BrTkCa 11,094 -
0
votes1
answer86
viewsA: post call does not work, returns error 405
He may be making one get due to the passage of arguments ?nd1=. When posting, it’s best to send data to the payload, not the URL. Fix for your case: Javascript <script type="text/javascript">…
-
1
votes2
answers920
viewsA: How to find an element within an object array by Id?
One can use the Array#splice to remove a certain index from the array. let a1 = [2,4,6], a2 = [ {id: 1, nome: "Teste 1"}, {id: 2, nome: "Teste 2"}, {id: 3, nome: "Teste 3"}, {id: 4, nome: "Teste…
-
2
votes3
answers1372
viewsA: Transforming String into an Array - Javascript
Assuming that the string is formatted correctly, you can parse for JSON: let str = '[[1, "X340H22G", 30000, 3],[2, "64418XL", 32000,1], [3, "X644X11L", 32000, 1]]'; let json = JSON.parse(str); //…
-
5
votes5
answers1186
viewsA: How to use the reduce (reduce) operation on objects?
The first parameter will accumulate the sum, an option for your case is also to indicate the initialization: const valores = [{valor: 1}, {valor: 2}, {valor: 3}, {valor: 4}, {valor: 5}, {valor:…