使用打字稿 - 订阅数据对象从 Angular2 应用程序中的 C# 元组访问 1 个属性



我有 2 个 c# 方法做完全相同的事情,但返回类型不同。 所以一个返回一个字符串,一个返回一个字节[]。 我认为重复的代码很混乱,现在正在尝试将其更改为一个 c# 方法并返回一个工作正常的元组。 问题出在我的角度 2(打字稿(中,我订阅了该方法并访问数据(曾经是一个字节[](,但现在它返回元组。 所以我的问题是如何访问我的数据。Item1(这是 Angular 2 打字稿中的字节数组(

this._repService.post(this.connStr + 'api/Report/RenderBoth?id=' + reportUrl + '&format=' +
                    exportType + '', paramArray
                ).subscribe(
                    data => {
                        if (data != null) { // Success

您可以创建自己的类型。

export type MyCustomTuple = [string, number, boolean];
var tuple1: MyCustomTuple = ["string", 1, false]; // OK
// var tuple2: MyCustomTuple = [1, "string", true]; // NOT OK, compile error
console.log(typeof (tuple1[0])); // always string
console.log(typeof (tuple1[1])); // always number
console.log(typeof (tuple1[2])); // always boolean

它有点像元组(不同类型的对象的有组织的集合(。

最新更新