Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm trying to display custom icons on a map and I'm almost there, I just have a simple issue that I can't find an answer to. There are three types of icon which correspond to data in the database in a column called 'Scarcity'. I have the data in an xml file and the icons display for 'Common' and 'Rare' but don't display for 'Very rare'. How do I capture this data with spaces in js?
The js I'm using for the icons is:
var customIcons = {
Common: {
icon: '../Images/Common.png'},
Rare: {
icon: '../Images/Rare.png'},
Very rare: {
icon: '../Images/veryRare.png'}
};
Thank you!
you will have to put keys in quotes like :
var customIcons = {
'Common': {
'icon': '../Images/Common.png'
},
'Rare': {
'icon': '../Images/Rare.png'
},
'Very rare': {
'icon': '../Images/veryRare.png'
}
};
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 months ago.
Improve this question
Consider this simple attempt to find a value in an object:
var config = {
product1: {
ids: ['master']
},
product2: {
ids: ['ps1', 'ps2']
}
};
var id = 'ps2';
var slotID = 'master';
var categorySlotIds = config[slotID].ids;
categorySlotIds.find(id);
I get: TypeError: Cannot find function find in object product1, product2
If I do typeof(categorySlotIDs) the result is object.
The manual for find says: The find() method returns the first element in the provided array
What gives?
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 months ago.
Improve this question
So my javascript file looks like this:
$(document).ready(function() {
var map = {
url: window.location.pathname //get URL without domain
};
$.post("/php/SongOutput.php", {map}).done(function(data){
console.log(map); //Check that the map is correct
console.log(data); //Show the value of $_POST["url"];
})
});
And the bit of php is the following:
echo $_POST["url"];
Now, as you can see what I'm trying to do is sending the current url of the site to php. But the only output I get from console.log(data); is null. How can I fix this?
you need to remove {} from second argument
$.post("/php/SongOutput.php", map).done(function(data){
console.log(map); //Check that the map is correct
console.log(data); //Show the value of $_POST["url"];
})
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Good day everyone,
I'm trying to convert the dates from my api using moment.js From my api, I have this kind of sample collection
I'm getting the same date like 2019-12-13 in all my dates.
Note: The problem is not in moment since it is working fine in my other codes. Just the forEach and I don't know which causes the problem.
const response = {
data: [{
'from': '2019-12-31T00:00:00',
'to': '2020-12-31T00:00:00'
},
{
'from': '2021-12-31T00:00:00',
'to': '2022-12-31T00:00:00'
},
{
'from': '2023-12-31T00:00:00',
'to': '2024-12-31T00:00:00'
}
]
}
response.data.forEach((d) => {
d.from = moment(response.data.from).format("YYYY-MM-DD")
d.to = moment(response.data.to).format("YYYY-MM-DD")
})
console.log(response.data)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
You aren't using d in your forEach loop - use d.to and d.from not response.data.to and response.data.from:
response.data.forEach((d)=>{
d.from = moment(d.from).format("YYYY-MM-DD")
d.to= moment(d.to).format("YYYY-MM-DD")
});
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
Hi I'm trying to print a list in which every entry should look like "element X of TOTAL" but instead of TOTAL i get only blank text.
I fell like it's something stupid but i can't figure out what.
This is from my html
<li ng-repeat="elem in lista" ng-show="check">
Elemento {{elem.item}} di {{len}}
<button ng-click="remove(elem)">Remove</button>
</li>
and here is from my app.js, which includes my controller
$scope.lista = [
{ item: 'uno' },
{ item: 'due' },
{ item: 'tre' }
];
var len = $scope.lista.lenght;
Change
var len = $scope.lista.lenght;
To :
$scope.len = $scope.lista.length;
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
var data = {};
data.info.id = "alpha";
This logs to the console: "TypeError: data.info is undefined".
Well that's great and all but I need to store a value in data.info.id. Isn't that what objects are supposed to do?
This should produce an object that looks like this:
data: {
info: {
id: "alpha"
}
}
Is data.info = {} really a necessary step?
In response to Patrick Evans - that's an unrelated question.
Well there is another way. That's putting the info-object directly in the data-object like this:
var data = {
info: {}
}
data.info.id = "alpha";
console.log(data);