小编KVN*_*VNA的帖子

如何从PWA App Home Screen Link中删除Chrome徽标(Android O预览版)

我刚刚更新到Android O Preview并安装了几个PWA.在主屏幕上,图标上放置了一个微型Chrome徽标.在操作系统更新之前,这不存在.

理想情况下,我希望PWA看起来像主屏幕上的常规应用程序,因为它启用了服务工作者.

是否可以通过app.yaml或manifest.json中的某些设置删除它?

android google-chrome homescreen progressive-web-apps

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

如何从不受欢迎的PUT请求中返回承诺

我正在尝试创建一个返回promise的函数,以便它可以链接在一起并与其他一些函数集成.

当我尝试运行时,我收到以下错误: TypeError: Cannot read property 'then' of undefined

我可以将诺言放在里面,.end还是需要将它包裹在整个函数体中?可以像这样妥善处理错误吗?

index.js

const module = require('./module');

var test = {
  name: "Full Name"
};

module.update(test).then((response) => {
  console.log(response);
});
Run Code Online (Sandbox Code Playgroud)

module.js

const unirest = require('unirest');

module.exports = {

update: function({name}) {
  unirest.put(someURL)
    .headers({
      'Content-Type': 'application/json'
    })
    .send({
      name: name
    })
    .end(function (response) {
      return new Promise((resolve, reject) => {
        if(response) {
          resolve(response)
        }
        if(error){
          reject(response)
        }
      })
  });
};
Run Code Online (Sandbox Code Playgroud)

javascript node.js promise unirest

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

Square nonce 代表什么?

我正在尝试向 Square 付款,但不确定这card_nonce代表什么。

在此处找到的完整 API 文档中:https : //docs.connect.squareup.com/api/connect/v2/#endpoint-createcustomercard

它指出,“代表信用卡链接到客户的卡随机数。”

但是,在此处找到的 REST 支付处理文档中:https : //docs.connect.squareup.com/articles/processing-payment-rest

它指出,“卡随机数在 24 小时后过期。如果您尝试对过期的随机数收费,则 Charge 端点将返回错误。”

  1. 如果我尝试存储一个card_nonce循环计费,我可以使用card_nonce一次并重复使用它进行计费吗?

  2. 客户每次要结账时是否都必须输入他们的卡信息?

  3. acard_nonce代表卡的状态,还是代表特定卡交易的密钥?

javascript square square-connect

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

如何传递Promise.all返回另一个函数Cloud Functions for Firebase

我试图从Firebase设置一些变量,然后将它们传递给一个anotherfunction.目前,Promise.all已正确设置foobar,但是,如果我不能告诉foobar被传递到then,而且火力地堡无法正常范围的.

Promise.all块基于以下教程:https://www.youtube.com/watch?v = NgZIb6Uwpjc&t = 305s

exports.someFunction = functions.database.ref(`/data`).onWrite(event => {
  const condition = event.data.val()
  if (condition) {
    // Get the data at this location only once, returns a promise, to ensure retrieval of foo and bar
    const foo = event.data.adminRef.child('foo').once('value')
    const bar = event.data.adminRef.child('bar').once('value')

    return Promise.all([foo, bar]).then(results => {
      const foo = results[0].val()
      const bar = results[1].val()
      // Properly sets …
Run Code Online (Sandbox Code Playgroud)

javascript node.js firebase google-cloud-functions

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

如何按嵌套值将嵌套对象数组分组为多个数组

我正在尝试按值将数组转换为一组新的数组,在本例中为id.

输入

let array = [
  {"item": {"id": 111, "name": "item1"}, "qty": 1}, 
  {"item": {"id": 222, "name": "item2"}, "qty": 2},
  {"item": {"id": 222, "name": "item3"}, "qty": 3}
];
Run Code Online (Sandbox Code Playgroud)

期望输出

let newArray = [
  [{"item": {"id": 111, "name": "item1"}, "qty": 1}], 
  [{"item": {"id": 222, "name": "item2"}, "qty": 2},
   {"item": {"id": 222, "name": "item3"}, "qty": 3}]
];
Run Code Online (Sandbox Code Playgroud)

使用标准groupBy函数,我们可以返回两个按 排序的数组id

function groupItemBy(array, property) {
  var hash = {};
  for (var i = 0; i < array.length; i++) …
Run Code Online (Sandbox Code Playgroud)

javascript arrays sorting grouping

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