在reducer中更新状态的更好方法是什么?
case DELETE_INTEREST:
let deleteInterests = state.user.interests;
let index = deleteInterests.findIndex(i => i == action.payload);
deleteInterests.splice(index, 1);
return { ...state, user: { ...state.user, interests: deleteInterests } };
Run Code Online (Sandbox Code Playgroud)
ESLint不喜欢在reducer中的case块内部使用let语句,得到:
eslint:no-case-declaration - case块中的意外词法声明
为什么这个文本没有显示在这个视图中?尝试在圆圈和文字上弯曲。我喜欢在海滩上散步并写一些额外的字符来使这篇文章变得活跃。
import React, {Component} from 'react';
import {View, StyleSheet, Text} from 'react-native';
export default class Interest extends Component {
constructor(props) {
super(props);
}
render() {
return(
<View style={styles.circle}>
<Text style={styles.text}>{this.props.title}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
circle: {
//flex: 1,
padding: 15,
borderRadius: 50,
borderWidth: 1,
borderColor: 'black',
height: 10,
minWidth: 80,
alignItems: 'center',
marginBottom: 10
},
text: {
//flex: 0,
fontFamily: "CircularStd-Book",
fontSize: 14,
color: '#2f354b',
textAlign: 'center'
}
});
Run Code Online (Sandbox Code Playgroud) 即使this.toilets充满了对象,我也收到了这个错误
日志首先显示this.location,然后是this.toilets,其中包含所显示的对象.
this.loadHomeData().then(data => {
this.toilets = data;
console.log(this.toilets);
});
Run Code Online (Sandbox Code Playgroud)
loadHomeData() {
return new Promise(resolve => {
this.http.get('http://url-to-my-server/' + this.location.coords.latitude + '/' + this.location.coords.longitude)
.map(res => res.json())
.subscribe(data => {
this.data = data;
resolve(this.data);
});
});
}
Run Code Online (Sandbox Code Playgroud)
this.toilets.forEach((toilet) => {
console.log(toilet);
});
Run Code Online (Sandbox Code Playgroud) 嘿家伙我正在尝试开发一个从数据库中返回趋势文章的查询.
热门文章基于过去24小时内的大多数观点.这是迄今为止的代码:
$trending = Article::whereHas('view', function ($query) {
$query->where('created_at', '>=', Carbon::now()->subHours(24));
})
->with('view')
->orderBy('created_at', 'DESC')
->get();
return $trending;
}
Run Code Online (Sandbox Code Playgroud)
文章模型具有以下关系:
public function view()
{
return $this->hasMany('ArticleView', 'article_id');
}
Run Code Online (Sandbox Code Playgroud)
该查询有效,但我还需要按视图计数对文章进行排序.例如,显示当前趋势文章,但具有最多视图计数的artticles不是从头到尾排序(显然 - 它们按created_at排序)
帮助赞赏
angular ×1
eloquent ×1
ionic2 ×1
javascript ×1
laravel ×1
react-native ×1
reactjs ×1
redux ×1
sorting ×1
trending ×1