JSON:
[
{
"1": "January",
"2": "February",
"8": "August",
"9": "Septemeber",
"10": "October",
"11": "November",
"12": "December"
},
{
"2": "February",
"3": "March",
"4": "April",
"5": "May",
"6": "June",
"7": "July",
"8": "August"
}
]
HTML:
<select class='W1_Normal V4 A_{{$parent.$index}}' style="width:100px;" id="A_{{$parent.$index}}_{{$index}}" name="A_{{$parent.$index}}_{{$index}}" onchange="modifiyOtherDropDowns(this);removeErrorMessagesOfAllLowerDivsUsingObj(this)">
<option value=""></option>
<option ng-repeat="(key, value) in ap" value="{{key}}">{{value}}</option>
</select>
In Firefox and Chrome, above written code is working fine, {{value}} is getting resolved corresponding value. But in IE {{value}} is getting showed as {{value}}!
UPDATE:Problem specific to IE8
You should read this article about using Angular with IE8 and earlier. There are some tricks you need to know about. Whenever I target IE8 with Angular, I avoid writing element directives and stick with attribute directives instead.
Related
I'm working on charts in React.js and i want to display data sorted by month. In django i've created view for displaying json with total events per month and it looks like this:
[
{
"month": "2022-06-01T00:00:00+02:00",
"total": 4
},
{
"month": "2022-08-01T00:00:00+02:00",
"total": 1
}
]
]
I would like to sort every object in that array and change value 'month' from numbers to month name, so it would be:
[
{
"month": "june",
"total": 4
},
{
"month": "august",
"total": 1
}
]
]
For generating charts i'm using chartist.
You could store the full date as a seperate key (called date), and set the month in a seperate function using a predefined array for the names of each month. Here is the code you would use:
const monthName = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"]; // Array representing each month
var chartItems = [
{
"date": "2022-06-01T00:00:00+02:00",
"month": null,
"total": 4
},
{
"date": "2022-08-01T00:00:00+02:00",
"month": null,
"total": 1
}
];
// Run through each item in the array
function setMonths(arr) {
arr.forEach(item => {
const date = new Date(item.date); // Convert date string to Date object
const monthIndex = date.getMonth(); // Get index of month from the Date
const month = monthName[monthIndex]; // Convert index into text representing the month
item.month = month; // Set the month key in the object to the new month
});
}
setMonths(chartItems); // Call function to set months in the array
As an alternative, you could also make a method for each object in the array that gets the month, but you would need to run this everytime you want to get the month. Here is the code for that:
const monthName = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
var chartItems = [
{
"date": "2022-06-01T00:00:00+02:00",
"month": function() { return monthName[new Date(this.date).getMonth()]; },
"total": 4
},
{
"date": "2022-08-01T00:00:00+02:00",
"month": function() { return monthName[new Date(this.date).getMonth()]; },
"total": 1
}
];
And you would get it like this:
chartItems[0].month(); // "[0]", meaning the first item in the array
I have an array and 2 variables. The two variables are numbers and the array contains 12 values.
const firstParam = 6;
const secondParam = 0;
originalArray = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
I want to take the numbers and check that index of the second array matches and then change the value of the matching ones.
In this case the output would be
newArray = ["blank", "February", "March", "April", "May", "June", "blank", "August", "September", "October", "November", "December"];
I was trying with map but it's not applied
const newArray = originalArray.map((element, index) => firstParam ? null : element);
How can I do it?
Is there any better way to get the desired result?
thanks for your help
You could take an array for the indices and check the index with Array#includes and return either a new value of the old value.
const
indices = [6, 0],
originalArray = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
result = originalArray.map((v, i) => indices.includes(i) ? 'blank' : v);
console.log(...result);
I am trying this mongo aggregation I got the output but my required output is not getting anyone please suggest my problem
const monthsEnum = {
"_id": "year",
"1": "January",
"2": "February",
"3": "March",
"4": "April",
"5": "May",
"6": "June",
"7": "July",
"8": "August",
"9": "September",
"10": "October",
"11": "November",
"12": "December"
};
Light.aggregate([
{ "$match": {
"CREATE_DATE": {
"$lte": new Date(),
"$gte": new Date(new Date().setDate(new Date().getDate()-120))
}
} },
{ "$group": {
"_id": {
"month": { "$month": "$CREATE_DATE" },
"year": { "$year": "$CREATE_DATE" }
},
"avgofozone": { "$avg": "$OZONE" }
} },
{ "$group": {
"_id": "$year",
"avgs": {
"$push": {
"k": { "$substr": ["$month", 0, -1 ] },
"v": "$avgofozone"
}
}
} },
{ "$replaceRoot": {
"newRoot": {
"$mergeObjects": [
{ "$arrayToObject": "$avgs" },
"$$ROOT"
]
}
} },
{ "$project": { "avgs": 0 } }
], (err, data) => {
console.log("naresh:" +JSON.stringify(data));
const polute = Object.keys(data).reduce((p, c) => ({...p, monthsEnum[c]: data[c]}), {});
res.json(polute);
})
output:
[
{
"zone_type": "avgofozone",
"year": 2018,
"February": 21.07777777777778,
"March": 17.8,
"January": 17.8
}
]
MY expected output is:
zone_type year February March January
avgofozone 2018 21.07777777777778 17.8 17.8
I am making a dropdown using this component
https://github.com/fraserxu/react-dropdown
I am calling it like this:
<Dropdown options={monthOptions} onChange={this.changeMonth} value={defaultMonth} placeholder="Select Month" />
Using this data:
export const monthOptions = [
"January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November", "December"
];
export const defaultMonth = "January";
And this method:
changeMonth: function(option) {
this.setState({month: option});
},
However, when I display the component in the browser, it is unresponsive. It doesn't show any options:
There is no message printed in the console.
This is about the ticks on axes in D3: Is there a way to replace the decimal dot with a comma in numbers? I want the numbers to be displayed like this (which is normal in Germany, such a big number is just for demonstration)
1.000.000,1 // This is one million and a tenth
and not like this:
1,000,000.1
I've read the documentation about the topic, but it seems like there is no possibility!? That's my relevant code so far:
localeFormatter = d3.locale({
"decimal": ".",
"thousands": ",",
"grouping": [3],
"currency": ["", "€"],
"dateTime": "%a, %e %b %Y, %X",
"date": "%d.%m.%Y",
"time": "%H:%M:%S",
"periods": ["", ""],
"days": ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
"shortDays": ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
"months": ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
"shortMonths": ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"]
});
numberFormat = localeFormatter.numberFormat("04.,"); // The setting is applied, but has not the desired effect...
yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.tickFormat(numberFormat);
Using the following settings for d3.locale:
var localeFormatter = d3.locale({
"decimal": ",",
"thousands": ".",
...
});
Note that I have changed the . in , and vice versa. And with:
var numberFormat = localeFormatter.numberFormat(",.2f");
I print the number using a thousands separator , (it uses a . as defined in the locale) and two digits after the comma .2f:
console.log(numberFormat(1000000.1)); // "1.000.000,10"