小编Ale*_*sky的帖子

Nuxt Ava 端到端测试存储配置

给出使用 Ava 的官方 Nuxt 端到端测试示例示例:

import test from 'ava'
import { Nuxt, Builder } from 'nuxt'
import { resolve } from 'path'

// We keep a reference to Nuxt so we can close
// the server at the end of the test
let nuxt = null

// Init Nuxt.js and start listening on localhost:4000
test.before('Init Nuxt.js', async t => {
  const rootDir = resolve(__dirname, '..')
  let config = {}
  try { config = require(resolve(rootDir, 'nuxt.config.js')) } catch (e) …
Run Code Online (Sandbox Code Playgroud)

ava vuex vuejs2 nuxt.js

5
推荐指数
1
解决办法
670
查看次数

通过es6在数组中查找不同的对象

我有一个像下面的数组

const data = [
    {
        name:'AAAA',
        group: 'A',
        age:10
    },
    {
        name:'ABCD',
        group: 'A',
        age:10
    },
    {
        name:'DJSHDJH',
        group: 'B',
        age:15
    },
    {
        name:'FJHF',
        group: 'B',
        age:20
    }
]
Run Code Online (Sandbox Code Playgroud)

我想找到不同的数据group,并age通过es6

预期结果

[
    {
        group: 'A',
        age: 10
    },
    {
        group: 'B',
        age: 15
    },
    {
        group: 'B',
        age: 20
    }
]
Run Code Online (Sandbox Code Playgroud)

我尝试过[... new Set(data.map(x => {x.group, g.age}))]但没有机会

我知道如何循环数据并找到唯一值,但我想使用es6函数

javascript arrays ecmascript-6

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

Azure函数JavaScript本地开发环境变量

在本地使用JavaScript开发Azure函数时,如何使用azure-functions-core-tools 在本地运行函数时获取/设置Node环境变量func host start --debug?

JavaScript中的Azure功能文档演示了目标功能应用程序设置process.env[settingName].当发布/部署从azure功能应用程序的应用程序设置中提取值时,这似乎很有效.

尝试在使用$env:FOO="bar"(powershell)或set FOO=bar命令提示符设置的函数内记录本地节点环境变量(Windows)时,它会记录未定义.尝试使用命令记录这些值context.log(process.env['FOO']).

index.js

const foo = process.env["FOO"];

module.exports = function (context, req) {
    context.log('bar') // successfully logs 'bar' in the azure function log
    context.log(foo); // logs undefined

    if (req.query.name || (req.body && req.body.name)) {
        context.res = {
            // status: 200, /* Defaults to 200 */
            body: "Hello " + (req.query.name || req.body.name)
        };
    } else {
        context.res = { …
Run Code Online (Sandbox Code Playgroud)

azure node.js azure-functions

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

吊索@Inject NullPointerError,当@Reference成功时

当尝试@Inject(javax.inject.Inject)注入MyConfigurationService内部@SlingServlet MyServlet导致NullPointerError任何时候myConfigurationService在使用Maven org.apache.felix.maven-scr-plugin作为构建过程的一部分的AEM OSGi容器内尝试任何操作.

服务实施:

@Service({MyConfigurationService.class})
@Component(immediate = true, metatype = true, label = "My Configuration Service")
public class MyConfigurationServiceImpl implements MyConfigurationService {
    @Property(unbounded = PropertyUnbounded.DEFAULT, label = "API URL", description = "API URL")
    private static final String API_URL = "apiurl";

    private String apiUrl;

    @Activate
    protected void activate(Map<String, Object> properties) {
        this.apiUrl = PropertiesUtil.toString(properties.get(API_URL), "");
    }
}
Run Code Online (Sandbox Code Playgroud)

Servlet的:

@SlingServlet(paths = "/bin/myServlet", methods = "POST", metatype = true)
public class …
Run Code Online (Sandbox Code Playgroud)

java osgi inject sling aem

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

Angular 6:将Observable响应传递给另一个Observable

我在使用angular typescript中的observable获取Web API输出时遇到问题.

我想获取第一个observable返回的值,然后将其值传递给另一个observable.到目前为止,这是我写的.

let output: any;
let output2: any;

_httpClient.get('http://localhost:5000/api/mycontroller')
  .subscribe((output_1) => {
    output = output_1;
  });

alert(output);

_httpClient.get('http://localhost:5000/api/mycontroller2'+output)
  .subscribe((output_2) => {
    output2 = output_2;        
  });
alert(output2);
Run Code Online (Sandbox Code Playgroud)

我在订阅的每个observable下面放置一个警报函数,检查每个响应返回的输出.

但是当我执行它并检查警告框中的输出时,它会为每个输出提供未定义的值.

如何强制observable提供来自我的Web API的输出?

rxjs asp.net-web-api typescript angular

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

ASP.NET Core 3.0 System.Text.Json Camel案例序列化

在ASP.NET Core 3.0 Web API项目中,如何指定System.Text.Json序列化选项以自动将Pascal Case属性序列化/反序列化为Camel Case,反之亦然?

给定具有Pascal Case属性的模型,例如:

public class Person
{
    public string Firstname { get; set; }
    public string Lastname { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

以及使用System.Text.Json将JSON字符串反序列化为Person类类型的代码:

var json = "{\"firstname\":\"John\",\"lastname\":\"Smith\"}";
var person = JsonSerializer.Deserialize<Person>(json);
Run Code Online (Sandbox Code Playgroud)

除非将JsonPropertyName与以下每个属性一起使用,否则不会成功反序列化:

public class Person
{
    [JsonPropertyName("firstname")
    public string Firstname { get; set; }
    [JsonPropertyName("lastname")
    public string Lastname { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我在中尝试了以下方法startup.cs,但在仍然需要方面没有帮助JsonPropertyName:

services.AddMvc().AddJsonOptions(options =>
{
    options.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase;
    options.JsonSerializerOptions.PropertyNamingPolicy = …
Run Code Online (Sandbox Code Playgroud)

c# json asp.net-core system.text.json

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

使用 xml2js 在 Angular 6 中未定义 parseString

到目前为止,我无法使用 Angular 6 让 xml2js 代码正常工作。我有一个 service.ts 返回 xml,但是当调用 xml2js.parseString 转换为 json 时,我始终收到未定义的错误。

“core.js:1673错误TypeError:无法读取未定义的属性'parseString'”

服务.ts

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, of } from 'rxjs';
import { map, filter, catchError, mergeMap } from 'rxjs/operators';
import { HttpHeaders } from '@angular/common/http';

export interface Zid {
  zpid: number;
}
const httpOptions = {
  headers: new HttpHeaders({
    'Content-Type': 'application/x-www-form-urlencoded',
  }),
  responseType: 'text' as 'text'
};    

@Injectable({
  providedIn: 'root'
})

export class CdataServiceService {

  constructor(private …
Run Code Online (Sandbox Code Playgroud)

xml json typescript xml2js angular

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

反应Redux Saga事件频道取消

是否有可能通过Redux Saga中的副作用之类的方法来取消eventChannel?

给定eventChannel与外部事件/数据流的连接,在这种情况下为Firebase实时数据库"child_added"事件:

// action
const types = { SYNC: 'SYNC_TODOS' };
function syncTodos(todos) {
    return { types: types.SYNC, todos }
}

// saga
function todosChannel() {
  // firebase database ref
  const ref = firebase.database().ref('todos/');

  const channel = eventChannel(emit => {
    const callback = ref.on('child_added', (data) => {
      emit({ snapshot: data, value: data.val() })
    });

    // unsubscribe function
    return () => ref.off('child_added', callback);
  });

  return channel;
}

function* sync() {
  const channel …
Run Code Online (Sandbox Code Playgroud)

reactjs redux redux-saga

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

Angular4 - 嵌套的Http调用

我在角度中使用http嵌套调用.

首先要求获得令牌. 第二次调用将使用令牌并返回实际数据.

  public get(api) {
    return this.http.get(this.url + '/token')
      .map(res => res.json())
      .toPromise()
      .then((data: any) => {
        this.access_token = data.access_token
        let headers = new Headers();
        headers.append('Authorization', 'Bearer ' + this.access_token);
        return this.http.get(this.url + api, {
          headers: headers
        }).map(res => res.json());
      })
  }
Run Code Online (Sandbox Code Playgroud)

该函数返回Promise<Observable<any>>.如何解析响应,以便我可以从订阅中的嵌套调用中获取数据.

this.get('me/profile')
    .subscribe(data => {
         console.log(data);
      });
Run Code Online (Sandbox Code Playgroud)

javascript rxjs angular

0
推荐指数
1
解决办法
3624
查看次数