Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
So I'm having some trouble. I have a map populated from a json file which works perfectly. However the client wants to truncate the description in the pin popup to 300 charters (rather than actually write text that fits). I thought I could change the description in the promise but it's not working, in fact it's having no effect at all. If anyone has an idea how to do this I'd really appreciate it.
fetch('/assets/map/markers.json')
.then(response => {
if (response.ok) {
return response.json();
}
throw new Error('Network response error.');
})
.then(charData => {
let mapData = charData.map(item => item.description.split(0, 300).join(" "));
createMap(mapData);
})
.catch(error => {
console.log('There has been a problem: ', error.message);
});
To take some characters out from a string you can use String.prototype.substring().
So change
item.description.split(0, 300).join(" ")
To
item.description.substring(0, 300)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I want to get values 0 from firebase realtime database as variable in JavaScript. have easy way to get it? (I tried to find from this website but there is only have android).
First you must get a reference to where the data is stored.
let ref = firebase.database().ref("database/path/to/limitedorder/Apoint");
Next, you must choose how you would like to be notified of data changes. For your use case, this would be subscribing to the 'value' event only once. This will return a Promise that resolves with the desired data.
let valuePromise = ref.once('value');
You then need to chain to the promise to handle/manipulate the data returned by the server and/or handle any errors.
valuePromise.then((dataSnapshot) => {
let desiredValue = dataSnapshot.val();
console.log("Desired value: ", desiredValue);
})
.catch((error) => {
console.log("An error occurred:", error);
})
Bringing this altogether gives:
firebase.database().ref("database/path/to/limitedorder/Apoint").once('value')
.then((dataSnapshot) => {
let desiredValue = dataSnapshot.val();
console.log("Desired value: ", desiredValue);
})
.catch((error) => {
console.log("An error occurred:", error);
})
Detailed explanation of these steps is provided in the Firebase RTDB for Web documentation.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I just cant seem to get the snapshot docs to show me the data from the server.
i have checked the collection. it is called "creaciones" without uppercase. I have 1 document and I have files written already. I've made no spelling mistakes whatsoever. I made this work before and now i cant.
ive tried using function "(querySnapshot){" but i got no positive results
//Setup grilla
const setupGrilla = (data) => {
let html = '';
data.forEach(doc => {
const grilla = doc.data();
const creacion = `
<div>
<img src='jpg/${grilla.tipoCreacion}.png' alt='tipoCreacion'>
<h2>${grilla.nombreCreacion}</h2>
<img src='Imagenes/${grilla.nombreFoto}' alt='nombrefoto' class='imagen'>
<span>piezas: ${grilla.piezas}</span>
<span class='separador'></span>
<span>tiempo: ${grilla.tiempo} minutos</span>
<p>padre: ${grilla.ayuda} </p>
<p class='puntos'>Puntos: ${grilla.puntos} </p>
</div>
`;
html += creacion;
});
}
//get Data
db.collection('creaciones').get().then(snapshot => {
setupGrilla(snapshot.docs);
console.log(snapshot.docs);
});
I expect it to fetch the database data.
I have already given you the answer here
You are passing the wrong argument in your method
db.collection('creaciones').get().then(snapshot => {
setupGrilla(snapshot);
});
And you can find the documentation here
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
this is my firebase database
- conversations (collection)
-- xxx (document)
--- users (collection)
---- xxx (document)
I want to list all the conversations and its users
this.db.collection('conversations').get().then(querySnapshot => {
querySnapshot.docs.forEach(doc => {
console.log(doc.collection('users').get())
});
});
I´m getting doc.collection is not a function
update: this is what I have after getting the id and making a new query. now the question is. is this performant?
this.db.collection('conversations').get().then(conversationsQuerySnapshot => {
conversationsQuerySnapshot.docs.forEach(doc => {
this.db.collection('conversations').doc(doc.id).collection('users').get().then(usersQuerySnapshot => {
usersQuerySnapshot.docs.forEach(doc => {
console.table(doc.data());
});
});
});
});
You're looking for doc.ref.collection('users'), since you need go get from the DocumentSnapshot to its DocumentReference through doc.ref.
Note that I find it easiest to spot such mistakes by simply following the types. Your querySnapshot is a QuerySnapshot, which means that your doc is a QueryDocumentSnapshot. Since QueryDocumentSnapshot doesn't have a collection method, it's easier to figure out what's going wrong.
you would call it: db.collection('conversations').doc({docID}).collection('users')
Your current query is set up to look through every conversation and then get every user in each of those. Plus the second part (getting the users) has no base document to pull from, which is why you're seeing an error.
I recommend watching this video
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have Two tables and table1 have multile ids of images and this images are stored in tabel 2 i am using for loop but it give me can't sent header error due to use of for loop.so what can i do please help
I am using mongo db
Use the 'async' NPM. Install the npm first with,
npm install async --save
Then use it in your code as follows,
const async = require('async');
async.forEach(Table1Ids, function (item, callback){
console.log(item); // print the id or object
table2.findOne({id: item.id}, function(err, doc){
if(err){
callback(err)
}else if (doc){
//Image fetch success. Use the doc here.
callback();
}else {
callback();
}
});
}, function(err) {
console.log('iterating done');
//You can respond from here.
});
Hope it helps...
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
When a user click's on a username on the list below, it's meant to open up the add user page with the name's of the user in the fields.
I get this error message:
Here's the code in the manage users page:
componentWillMount: function () {
var userId = this.props.params.id; // from the path /user:id
if (userId) {
this.setState({ user: userId.getUserById(userId) });
}
},
Here's the code in the userApi:
getUserById: function(id) {
var user = _.find(users, {id: id});
return _clone(user);
},
I am new to StackOverflow and programming, so if this post doesn't meet the community's guidelines, please guide me on how to better make use this platform so I can further my learning progression.
Thanks,
Rickie
Using the userId variable you can't call your API. Since getUserById is from your API you must call the method from there.
userApi.getUserById(userId);