小编Phi*_*hix的帖子

如何在打字稿中使用带有变量的可选链运算符

我有以下代码,我想从变量对象的值键传递数字,如何使用变量作为可选链运算符来解决错误元素隐式具有any类型?

    function fun(i?: number) {
        console.log(i)
    }

    const variable = { min: { value: 1, name: 'google' }, max: {value: 2, name: 'apple'} }
    const variable2 = { min: { value: 1, name: 'google' } }
    const variable3 = { max: {value: 2, name: 'apple'} }

    fun(variable?.min.value) // working => 1
    fun(variable?.max.value) // working => 2
    fun(variable2?.min.value) // working => 1
    fun(variable2?.max.value) // working => undefined
    fun(variable3?.min.value) // working => undefined
    fun(variable3?.max.value) // working => 2

    Object.keys(variable).forEach((key) => …
Run Code Online (Sandbox Code Playgroud)

javascript typescript typescript1.5 typescript1.9 typescript2.0

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

角度6 ResponseContentType

我正在尝试从我的api rest下载一些xls,但无济于事,我是否需要使用ResponseContentType的东西?

[ts] O módulo '"/home/dev/Documentos/JAVA-TUDO/SIMPLUS/simplus-cliente/node_modules/@angular/common/http"' não tem nenhum membro exportado 'ResponseContentType'.


import ResponseContentType
import { Injectable } from '@angular/core';
import { HttpClient, ResponseContentType } from '@angular/common/http';
import { Product } from '../model/product.model';

@Injectable()
export class ProductService {
Run Code Online (Sandbox Code Playgroud)

api rest xls spring-boot angular

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

ADT20和外部JAR

在此输入图像描述在尝试使用外部jar时,我已经尝试了一切以避免NoClassDefFoundError.没有骰子.WTF ADT?!

从一个干净的全新项目中,添加外部jar来构建路径,放入libs文件夹,确保它已被检查.Android - >修复项目属性,添加和删除,冲洗和重复.我检查了jar的内容,我的文件就在那里!我引用了20种方式,删除了添加和重建,仍然无法找到真正的东西!!

从步骤1开始,有没有人使用eclipse和ADT 20在Android内部制作外部jar工作?

编辑1

我尝试将它添加到libs/文件夹中,并尝试了阿里在这个SO问题中提出的建议.我想我将不得不尝试直接将源添加到我的项目中,但这看起来很愚蠢.

java android jar adt

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

Dojox/mvc /在型号范围内

在dojox/mvc包中使用Stateful对象时,声明性示例似乎在全局命名空间中具有目标模型(在没有"var"关键字的情况下定义).这通过污染全局命名空间违反了良好Javascript设计的一般做法,更不用说使用不同的模型变得困难和混乱.

我的问题是,()声明的范围是什么,以及如何使用位于特定上下文/范围内的模型?

http://dojotoolkit.org/reference-guide/1.9/dojox/mvc.html#id6

model-view-controller dojo

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

JavaScript位掩码

我以前在Java(不是Javascript)中使用过位掩码,但是已经有一段时间了,这让我很烦。

这是我要使用的打字稿。有3个角色,

enum Type {
    FRUIT = 0x1,
    VEGGIE = 0x2,
    BOTH = FRUIT | VEGGIE
}

class Thing {
    role:number;

    constructor(role:Type){
        this.role = role;
    }
    getRole(){
        return this.role;
    }
    is(role:Type) {
        return !!(this.role & role);
    }
}

var whatever = new Thing(Type.FRUIT);

console.log('fruit', whatever.is(Type.FRUIT));
console.log('veggie', whatever.is(Type.VEGGIE));
console.log('both', whatever.is(Type.BOTH));

// fruit true
// veggie false
// both true
Run Code Online (Sandbox Code Playgroud)

我从概念上了解了为什么“两个”又返回“真实”,但是我的数学并不好。

当角色为FRUIT或时VEGGIE,其他角色为false。设置为时BOTH,所有设置都应为true。

尝试了一些移位和位运算的组合,但我无法获得该输出。如果我尝试将它们分开,那很好,但是我想使用位组合来构建。

javascript bit-manipulation bitmask typescript

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