小编Tra*_*rax的帖子

获取 _flutter 在 flutter web 中未定义,仅在生产中定义

我在最近几次部署中出现了一个错误,但无法追踪它。仅当我部署到 firebase 网站时才会发生这种情况,调试工作没有任何问题。

Uncaught SyntaxError: Unexpected token '<' (at flutter.js:1:1)
(index):50 Uncaught ReferenceError: _flutter is not defined
    at (index):50:7
Run Code Online (Sandbox Code Playgroud)

这显示在浏览器控制台中。

这是我的index.html:

<!DOCTYPE html>
<html>

<head>
  <!--
    If you are serving your web app in a path other than the root, change the
    href value below to reflect the base path you are serving from.

    The path provided below has to start and end with a slash "/" in order for
    it to work correctly.

    For more details:
    * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

    This …
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-web

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

Javascript多次推送/移动相同的元素

我有以下代码:

var foo = 'foo'
var bar = 'bar'
var arr = [1,2,3]
Run Code Online (Sandbox Code Playgroud)

我想foo在数组的开头和数组bar的末尾多次添加.每个元素添加的次数应该是动态的,结果数组应该是这样的:

['foo','foo',1,2,3,'bar',bar','bar']

有没有比为每个元素使用循环更好的方法?如果需要,我可以使用lodash.

javascript arrays push

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

JS Retry函数多次查看它是否返回true

我正在寻找一种更好的方法来重试函数是否返回true或false

   function foo() { // 
        var tabList = window.content.document.getElementById('compTabs') // this might be null if page is not loaded and further code wont work
        if (!tabList) { // stop here if tab list is null
            return false;
        }
    // continue and finish function
        }


// this is a loop that will go trough an array and this check needs to happen for each element of the array 
for (var i; i < loopLenght; i++) {
    // This is the actual …
Run Code Online (Sandbox Code Playgroud)

javascript

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

Javascript将Promise放入数组

我正在尝试创建一个Promise数组,并用来调用它们Promise.all

我在将函数正确推入数组时遇到麻烦,似乎正在调用它们,而不是插入并等待Promise.all()

function findSpecialAbility(players, gameId, message) {
  return new Promise(function(resolve, reject) {
    let playersWithSpecials = _.reject(players, function(p) {
      return p.role === 'alphaWolf' ||
        p.role === 'betaWolf' ||
        p.role === 'villager' ||
        p.role === 'alchemist' ||
        p.targetId === 0 ||
        p.abilityUsed === true;
    });
    if (playersWithSpecials.length === 0) {
      resolve();
    } else {
      let specialsToUse = [];
      for (let i = 0, j = playersWithSpecials.length; i < j; i++) {
        specialsToUse.push(useSpecialAbility(playersWithSpecials[i], gameId, message, players));
      }
      //Promise.all(specialsToUse).then(r = …
Run Code Online (Sandbox Code Playgroud)

javascript arrays function es6-promise

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

反应原生谷歌登录开发者错误代码 10

我正在尝试在我的项目中使用带有 firebase 的 google 登录。我以前使用过它并且成功了,但这次我无法使它工作,请遵循所有正确的步骤。使用反应原生 0.60。

GitHub 上的疑难解答建议添加signingConfigs到 build.gradle,但它已经在那里了。SHA 密钥是正确的,在另一个项目中使用它并且工作正常,唯一的区别是 react-native 0.59

Create new fire base project Choose a Google Cloud Platform (GCP) resource location Set support email Enable Google Auth Added the Web Client ID from Google Auth to project config SHA Key generated with keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore // Same key worked with other project Placed google-services.json in app/ // Content matches the web client id from page and project config Added all …

android firebase react-native firebase-authentication google-signin

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

基于条件语句的多参数调用函数

标题说明了一切我有以下功能:

var foo = function(arg1, arg2,arg3) {
    // code
}
Run Code Online (Sandbox Code Playgroud)

我想做类似的事情:

foo('bar', (x == true ? arg2, arg3 : arg2,arg3))
Run Code Online (Sandbox Code Playgroud)

但是我遇到了SyntaxError: Unexpected token ,做这样的事情的正确语法是什么?

javascript function conditional-statements

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

Node.js res.send VS res.end VS返回res.end

我有以下代码在mongodb findAndUpdateOne更新查询中有语法错误.

router.post('/buylicense', isLoggedIn, function(req, res) {
    if (!req.body.cid) {
        return res.send('failed');
    }
    Company.findOne({
        ownedBy: req.user.local.username,
        _id: req.body.cid
    }, function(err, result) {
        if (err) {
            return res.send('failed');
        }
        if (result.license) {
            return res.send('valid');
        } else {
            Company.findOneAndUpdate({
                ownedBy: req.user.local.username,
                _id: req.body.cid
            }, {
                license: true,
                licenseExpireDate: {
                    $add: ["$date", 3 * 24 * 60 * 60000] // bad code, a problem for another day
                }
            }, function(err) {
                if (err) {
                  console.log(err);
                  return res.end('failed'); // Code should stop here.
                } …
Run Code Online (Sandbox Code Playgroud)

mongodb node.js express

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

Firebase/Firestore 数据不是函数

我正在尝试使用 firebase 云函数内的 where 子句进行简单的 firestore 查询,但我得到了foo.data is not a function.

exports.uploadList = functions.https.onRequest(async (req, res) => {
 try {
    let foo = await db.collection('users').where('appToken', '==', 'xxxx').get()
    if (foo) {
      return res.status(200).send({ foo: foo.data() })
    }
  } catch (error) {
    return res.status(500).send(error)
  }
})
Run Code Online (Sandbox Code Playgroud)

我得到的响应是一个空对象{},如果删除 try/catch 块,我可以在云函数日志中看到错误foo.data is not a function

我读到这where()是可选的,所以也尝试过db.collection('users').get(),结果相同。

我可以使用查询db.collection().doc().get(),它工作正常,但无法通过字段值查找文档。set并且update工作也很好。

firebase google-cloud-functions google-cloud-firestore

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