小编Sed*_*rei的帖子

ts ES5/ES3中的异步函数或方法需要'Promise'构造函数

你好我在我的TypeScript项目中使用async/await但是我得到这个日志:

[ts] ES5/ES3中的异步函数或方法需要'Promise'构造函数.确保您有"Promise"构造函数的声明或在您的--lib选项中包含"ES2015" .

我该如何解决这个问题?

async-await typescript

81
推荐指数
5
解决办法
5万
查看次数

长时间设置计时器,即多分钟

我想使用firebase auth with native for Login,Signup但是我得到了一个黄色错误:

长时间(即多分钟)设置计时器是Android上的性能和正确性问题,因为它使计时器模块保持唤醒状态,并且只有在应用程序位于前台时才能调用计时器.有关详细信息,请参阅(https://github.com/facebook/react-native/issues/12981).(看到setTimeout,持续时间为111862ms)

我该如何解决这个问题?
我不想忽视这一点,我想理解这个错误并用最好的标准方式解决这个问题.
这是我的代码:

  export default class Login extends Component {
        constructor(props) {
            super(props)
            this.state = {
                email: '',
                password: '',
                response: ''
            }
            this.signUp = this.signUp.bind(this)
            this.login = this.login.bind(this)
        }
        async signUp() {
            try {
                await firebase.auth().createUserWithEmailAndPassword(this.state.email, this.state.password)
                this.setState({
                    response: 'Account Created!'
                })
                setTimeout(() => {
                    this.props.navigator.push({
                        id: 'App'
                    })
                }, 1500)
            } catch (error) {
                this.setState({
                    response: error.toString()
                })
            }
        }
        async login() {
            try {
                await …
Run Code Online (Sandbox Code Playgroud)

javascript firebase react-native

46
推荐指数
6
解决办法
1万
查看次数

获取undefined不是评估_this.props.navigation的对象

我使用DrawerNavigator,我有3页:Router page,mainScreenphotos page,
我maked头导航栏区域,我用这个<TouchableHighlight onPress={() => this.props.navigation.navigate('DrawerOpen')}>在mainScreen打开抽屉菜单,并使用提供的照片太过页面,菜单是确定在mainScreen,但是当我点击<TouchableHighlight onPress={() => this.props.navigation.navigate('DrawerOpen')}>的照片页面,我收到此错误: 照片
我该如何解决这个问题?

我的照片页面:

import React from 'react';
import { Button, ScrollView, View, Text, StyleSheet, TouchableHighlight } from 'react-native';
import { DrawerNavigator } from 'react-navigation';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
import Icon from 'react-native-vector-icons/FontAwesome'

const MyNavScreen = ({ navigation }) => (
  <View>
    <View style={styles.containerNavbar}>
      <TouchableHighlight onPress={() => this.props.navigation.navigate('DrawerOpen')}>
        <Icon name="bars" size={30} color="#fff" />
      </TouchableHighlight>
      <Text style={styles.navbarTitle}>Photos</Text>
    </View>

    <ScrollView>
      <View><Text>photo</Text></View>
      <Button …
Run Code Online (Sandbox Code Playgroud)

react-native react-navigation

26
推荐指数
5
解决办法
5万
查看次数

语法错误:缺少)参数列表后,使用异步时

我使用时为什么会收到此错误async

我的代码:

bot.onText(/\/start/, async  msg => {
  const opts = {
    parse_mode: 'Markdown' ,
    reply_markup: JSON.stringify({
      keyboard: StartKeyboard,
      resize_keyboard: true,
      one_time_keyboard: true
    })
  };
  await bot.sendMessage(msg.chat.id, 'Hi', opts);
});
Run Code Online (Sandbox Code Playgroud)

错误:

bot.onText(/\/start/, async  msg => {
                      ^^^^^
SyntaxError: missing ) after argument list
Run Code Online (Sandbox Code Playgroud)

我正在使用node.js v6.11.0和"dependencies":

{ "babel-polyfill": "^6.23.0",
  "cheerio": "^1.0.0-rc.2",
  "dotenv": "^4.0.0",
  "firebase": "^4.1.2",
  "firebase-admin": "^5.0.0",
  "node-telegram-bot-api": "^0.27.1",
  "request": "^2.81.0" },
Run Code Online (Sandbox Code Playgroud)

javascript node.js async-await telegram-bot

16
推荐指数
2
解决办法
8706
查看次数

循环中出现意外的"等待".(无AWAIT在回路)

我该如何等待bot.sendMessage()循环内部?
也许我需要,await Promise.all但我不知道我应该如何添加bot.sendMessage()

码:

  const promise = query.exec();
  promise.then(async (doc) => {
    let count = 0;
    for (const val of Object.values(doc)) {
      ++count;
      await bot.sendMessage(msg.chat.id, ` ${count} and ${val.text}`, opts);
    }
  }).catch((err) => {
    if (err) {
      console.log(err);
    }
  });
Run Code Online (Sandbox Code Playgroud)

错误:

[eslint] Unexpected `await` inside a loop. (no-await-in-loop)
Run Code Online (Sandbox Code Playgroud)

javascript async-await

12
推荐指数
2
解决办法
1万
查看次数

RTL 中的 LTR 设备反应原生

新问题

我的应用程序Left to Right只是当有人用阿拉伯语手机打开我的应用程序时,所有的样式都会出现Right to Left

如何让我的 APP 在所有语言中从左到右修复静态?

right-to-left react-native

9
推荐指数
2
解决办法
3266
查看次数

通过本机反应传递复选框值以显示/隐藏密码

我正在使用 Firebase auth 我想添加一个复选框,它将在密码文本框中显示密码并在再次单击时隐藏它

如何传递复选框值以显示/隐藏密码?

这是我的登录页面代码:

export default class Login extends Component {
    constructor(props) {
        super(props)
        this.state = {
            email: '',
            password: '',
            response: ''
        }
        this.signUp = this.signUp.bind(this)
        this.login = this.login.bind(this)
    }

    async signUp() {
        try {
            await firebase.auth().createUserWithEmailAndPassword(this.state.email, this.state.password)
            this.setState({
                response: 'Account Created!'
            })
            setTimeout(() => {
                this.props.navigator.push({
                    id: 'App'
                })
            }, 500)
        } catch (error) {
            this.setState({
                response: error.toString()
            })
        }
    }
    async login() {
        try {
            await firebase.auth().signInWithEmailAndPassword(this.state.email, this.state.password)
            this.setState({
                response: 'user login in'
            })

            setTimeout(() …
Run Code Online (Sandbox Code Playgroud)

javascript firebase react-native firebase-authentication

8
推荐指数
3
解决办法
2万
查看次数

如何在React Native for Android中的启动画面后删除白色屏幕

我有一个Default react本机项目,我安装了From This Turorial,我刚刚使用本教程将Splash Screen添加到我的项目中,但我得到了第一个:

  • 0.5下降闪屏照片
  • 然后1.5分白屏
  • 然后,我的应用程序启动,

解决此问题的最佳和最常用的方法是什么? 我需要只有1个标准预加载启动屏幕和该应用程序启动之后,我阅读更多文章,但我不能通过本机反应修复.

<application
  android:name=".MainApplication"
  android:allowBackup="true"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:theme="@style/AppTheme">
  <activity
    android:name=".SplashActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:windowSoftInputMode="adjustResize"
    android:theme="@style/SplashTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
  <activity android:name=".MainActivity" />
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
Run Code Online (Sandbox Code Playgroud)

splash-screen react-native

7
推荐指数
4
解决办法
1万
查看次数

如何通过PHP将网站中的整个数字替换为波斯语数字?

如何通过PHP将身体或网站html中的整个数字替换为波斯数字?
我想替换我网站上所有页面的所有数字.

码:

function ta_persian_num($string) {
  //arrays of persian and latin numbers
  $persian_num = array('?', '?', '?', '?', '?', '?', '?', '?', '?', '?');
  $latin_num = range(0, 9);

  $string = str_replace($latin_num, $persian_num, $string);

  return $string;
}
Run Code Online (Sandbox Code Playgroud)

我的代码适用于客户端:

<script>
    $(document).ready(function(){
    persian={0:'?',1:'?',2:'?',3:'?',4:'?',5:'?',6:'?',7:'?',8:'?',9:'?'};
    function traverse(el){
        if(el.nodeType==3){
            var list=el.data.match(/[0-9]/g);
            if(list!=null && list.length!=0){
                for(var i=0;i<list.length;i++)
                    el.data=el.data.replace(list[i],persian[list[i]]);
            }
        }
        for(var i=0;i<el.childNodes.length;i++){
            traverse(el.childNodes[i]);
        }
    }
    traverse(document.body);
});
</script>
Run Code Online (Sandbox Code Playgroud)

php

7
推荐指数
1
解决办法
356
查看次数

“{”之后不应有空格(babel/object-curly-spacing)

我正在使用shift + alt + f它来对代码进行排序vscode,但为什么我会收到此错误:?

错误:

[eslint] There should be no space after '{' (babel/object-curly-spacing)
Run Code Online (Sandbox Code Playgroud)

代码:

 User.findOne({ _id: temp }, (obj) => {
Run Code Online (Sandbox Code Playgroud)

删除 _id 之前和 temp 之后的空格后,我没有任何错误,但我应该如何修复 vscode 中的自动排列?

javascript eslint visual-studio-code

6
推荐指数
3
解决办法
1万
查看次数