如何使用IF语句检查数组是否为空?
我有这个数组'acessos'是空的
...
constructor(props){
super(props);
this.state = {
acessos:[]
};
}
...
Run Code Online (Sandbox Code Playgroud)
然后我试图检查'acessos'是否为空,如果是,我在其中推送一些数据.我已尝试使用null但没有结果,那么如何检查是否为空?
...
if(this.state.acessos === null){
this.state.acessos.push({'uuid': beacons.uuid, 'date':date});
this.setState({acessos: this.state.acessos});
} else {
...
Run Code Online (Sandbox Code Playgroud) 我正在触摸(滚动)而不是像它应该的那样(猜测)点击时触发涟漪效应。这发生在ion-ripple-effect标签上或离子标签中,默认情况下具有涟漪效应(如ion-item)。
这是我使用的代码片段ion-ripple-effect tag:
<ion-row class="dash ion-margin-top">
<ion-col size-xs="6" size-sm="4" size-md="3" *ngFor="let item of dash">
<div class="box shadow">
<div class="content ion-activatable" routerLink="{{item.route}}">
<ion-icon name="{{ item.icon }}" color="primary"></ion-icon>
<ion-label color="dark">{{ item.name }}</ion-label>
<ion-ripple-effect></ion-ripple-effect>
</div>
</div>
</ion-col>
</ion-row>
Run Code Online (Sandbox Code Playgroud)
有没有人遇到过这个,如果有,知道谁来解决它?
提前致谢。
我想知道如何删除活动存储中的所有数据,甚至重置活动存储?有什么办法吗?先感谢您!
注意:我正在使用Rails 5.2
在更新到 Rails 5.2 之前,我通过回形针图像创建了 MD5 哈希值,如下所示:json.image_md5 Digest::MD5.file(monument.image.path(:mobile)).hexdigest
现在,有了 Active Storage,我该如何做同样的事情呢?我已经尝试过了:
json.image_md5 Digest::MD5.file(url_for(monument.cover_image)).hexdigest
json.image_md5 Digest::MD5.file(rails_blob_path(monument.cover_image)).hexdigest
json.image_md5 Digest::MD5.file(Rails.application.routes.url_helpers.rails_blob_path(monument.cover_image, only_path: true)).hexdigest
Run Code Online (Sandbox Code Playgroud)
但没有成功。我收到一个错误No such file or directory。
你能帮助我吗?谢谢你!
ruby-on-rails ruby-on-rails-5 rails-activestorage ruby-on-rails-5.2
我有一个应用程序,当用户登录时,他收到了一些数据作为响应,但如果响应不是我所期望的,应用程序就会崩溃。
让我向您展示以下内容:
我创建了一个接口来告诉 Typescript 我期望的数据。
export interface AuthResponseData {
token: string;
expires: string;
role: number;
}
Run Code Online (Sandbox Code Playgroud)
然后我创建了一个方法来将登录数据发送到服务器。
login(user: string, password: string){
return this.http.post<AuthResponseData>(
'https://localhost:44344/api/auth', { user: user, pwd: password }
).pipe(
catchError(this.handleError),
tap(resData => { this.handleAuthentication(resData.token, resData.expires, resData.role)})
);
}
Run Code Online (Sandbox Code Playgroud)
我期待如果来自服务器的响应与接口不匹配,那么 Angular 将重定向到catchError. 但不会发生。
现在我的问题是:有什么方法可以检查 API 响应是否等于接口,如果不是则抛出错误。或者我问的是不可能的?
更新:
搜索后,我发现接口在运行时消失了,因此无法将 api 响应与接口进行比较(据我所知)。但我一直在寻找一种以动态方式检查 api 响应的方法。我认为取决于 api 响应总是正确的,这并不是真正安全的。所以我应该检查 API 响应。我怎样才能做到这一点?
希望你能帮助我,谢谢:)
我正在创建一个从 fetch 函数获取一些数据的应用程序。这里没问题。数组的数据正确。我这样做是这样的:
constructor(){
super()
this.state = {
fetching: false,
api: []
}
}
componentWillMount(){
this.setState({ fetching: true })
api.getMonuments().then(res => {
this.setState({
api: res,
fetching: false
})
})
}
Run Code Online (Sandbox Code Playgroud)
然后我想将该数据传递到另一个场景。我这样做是这样的:
<View style={styles.contentContainer}>
<TouchableHighlight
style={[styles.button, {marginBottom:0}]}
onPress={() => navigate('Monumento', this.state.api)}
underlayColor='#000'
>
<View style={styles.buttonContent}>
<Animatable.Text
style={styles.buttonText}
animation="bounceInLeft"
duration={1500}
>
Click here!
</Animatable.Text>
</View>
</TouchableHighlight>
</View>
Run Code Online (Sandbox Code Playgroud)
在另一个场景中,我使用 navigation.state.params 获取该数据,但现在的问题是不再有一个包含 4 个对象的数组,而是一个包含 4 个对象的对象......如果我控制台记录所显示的数据
render(){
const api = this.props.navigation.state.params;
console.log('API:', api)
...
Run Code Online (Sandbox Code Playgroud)
现在我想使用地图函数,但我不能,因为“api”不是函数......我该如何解决这个问题?
我现在为此苦苦挣扎了一天,可能真的很容易解决。
我想要的是只接受数字的搜索字段,所以我尝试了这样的事情:
function onlyNumbers(){
$('.select2-search__field').on('keypress', function () {
$(this).val($(this).val().replace(/[^\d].+/, ""));
if ((event.which < 48 || event.which > 57)) {
event.preventDefault();
}
});
}
function select2(){
$(".select2From").select2({
tags: true,
placeholder: "de",
allowClear: true
});
$(".select2To").select2({
tags: true,
placeholder: "até",
allowClear: true
});
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用……实际上我什至无法访问'.select2-search__field'. 是否在按键、更改、点击、某些东西上都无关紧要......我只想知道如何获得该输入,以便我可以过滤输入中的文本。
希望您能够帮助我。谢谢!
首先我不知道这是否是一个错误。到目前为止,我一直在 rails development.rb 环境配置中使用此命令,以便该框检测我的文件的更改:
config.reload_classes_only_on_change = false
但是现在,使用 Rails 5.2 和 Active Storage,该命令会使服务器变慢,并且加载图像需要 10 到 40 秒。
这是一个错误吗?还有另一种方法可以让 vagrant/rails 检测我的文件中的更改,而不必每次更改某些内容时都重新加载服务器?
希望你能帮我!此致
ruby-on-rails vagrant vagrantfile ruby-on-rails-5 rails-activestorage
react-native ×2
angular ×1
angular8 ×1
ionic5 ×1
javascript ×1
jquery ×1
reactjs ×1
ruby ×1
typescript ×1
vagrant ×1
vagrantfile ×1