当前位置:网站首页>JS ternary operator - learning notes (with cases)
JS ternary operator - learning notes (with cases)
2022-07-03 08:40:00 【Rain shallow listen to the wind sing】
Detailed explanation
react Case study
Hope to have color Attribute event Use color attribute , No, color The current time period of the attribute is gray , Then green
color:event.color?event.color:((new Date(event.start))>(new Date())?'green':'gray'),
onPageChange = (data: OnPageChangeData) => {
this.setState({
"eventList":{
}});
axios.post('api/oa/work/report/findMyAll', Qs.stringify({
start:moment(data.rangeFrom).format('YYYY-MM-DD HH:mm:ss'),
end:moment(data.rangeTo).format('YYYY-MM-DD HH:mm:ss')
}),{
headers: {
'Content-Type': 'application/x-www-form-urlencoded'}})
.then((response)=>{
let data=response.data.data;
for(let i=0;i<data.length;i++){
if(data[i]["type"]=='WEEK'){
data[i]["color"]='blue'
}
}
console.log(data)
let stateEventList=this.state.eventList;
for(let i=1;i<data.length;i++){
let event=data[i];
let eventDate=moment(event.start).format('DD-MM-YYYY HH:mm:ss').substring(0,10);
if (stateEventList[eventDate]==undefined){
let newEventList= new Array()
stateEventList[eventDate]=newEventList
}
let newEvent={
id:event.id,
startAt: moment(event.start).utc().format(),
endAt: moment(event.end).utc().format(),
summary: event.title,
type:event.type,
workContent:event.workContent,
// color:(new Date(event.start))>(new Date())?'green':'gray',
color:event.color?event.color:((new Date(event.start))>(new Date())?'green':'gray'),
};
stateEventList[eventDate].push(newEvent);
}
this.setState({
eventList:stateEventList})
console.log('this.eventList',this.eventList)
})
.catch(function (error) {
this.showErrorMessage(error);
});
}
边栏推荐
- [MySQL] MySQL Performance Optimization Practice: introduction of database lock and index search principle
- Unity learning notes
- OpenGL learning notes
- Gradle's method of dynamically modifying APK package name
- [cloud native] introduction and use of feign of microservices
- Exe file running window embedding QT window
- Visual Studio (VS) shortcut keys
- Osgearth north arrow display
- Mxone Pro adaptive 2.0 film and television template watermelon video theme apple cmsv10 template
- Vscode, idea, VIM development tool shortcut keys
猜你喜欢
随机推荐
[rust notes] 09- special types and generics
【更新中】微信小程序学习笔记_3
Encoding and decoding of golang URL
Final review of Database Principles
Student educational administration management system of C # curriculum design
Ue5 opencv plug-in use
Collection interface
matlab神经网络所有传递函数(激活函数)公式详解
Image processing 8-cnn image classification
Simply start with the essence and principle of SOM neural network
Unity editor expansion - the framework and context of unity imgui
Unity4.3.1 engine source code compilation process
Location of package cache downloaded by unity packagemanager
[rust notes] 12 closure
Markdown learning
796 · unlock
Unity editor expansion - window, sub window, menu, right-click menu (context menu)
[concurrent programming] collaboration between threads
[concurrent programming] consistency hash
Find the intersection of line segments