Clarity Datagrid & Promise / 主题绑定列
Clarity Datagrid & Promise / Subject Bound Column
我有一个数据网格,其中一列专门绑定到一个函数调用。
<clr-dg-column [clrDgField]="'Id'">ID</clr-dg-column>
<clr-dg-column [clrDgField]="'Client'">Client</clr-dg-column>
<clr-dg-column [clrDgField]="'Name'" [clrDgSortOrder]="ClrDatagridSortOrder.ASC">Name</clr-dg-column>
<clr-dg-column [clrDgField]="'PublicKeyHash'">Public Key Hash</clr-dg-column>
<clr-dg-row *clrDgItems="let clientLicense of ClientLicenses" [clrDgItem]="clientLicense">
<clr-dg-cell>{{clientLicense.Id}}</clr-dg-cell>
<clr-dg-cell>
{{getClientName(clientLicense.ClientId)}}
</clr-dg-cell>
<clr-dg-cell>{{clientLicense.Name}}</clr-dg-cell>
<clr-dg-cell>{{clientLicense.PublicKeyHash}}</clr-dg-cell>
</clr-dg-row>
参见第二列,我们称之为"getClientName(clientLicense.ClientId)"。该方法需要异步运行;也就是说,根据请求它不会立即具有值。我对 Typescript / Angular 有点新,但我相信我正在寻找 return Promise 或 BehaviorSubject(到目前为止,我在从我的记录中检索记录时已经广泛使用了这些通过方法调用而不是绑定/订阅存储库)。
所以,我试过 return 一个 Promise、BehaviorSubject、AsyncSubject 都得到了相同的结果——整个网络浏览器都死死锁住了,我不得不结束进程(笑)。
我知道绑定到 属性 或在我的视图模型上预填充 属性 是最简单的;但是由于体系结构,这并不容易......我基本上有两个相关的独立存储库。外键;我正在根据许可证上的客户端 ID 从客户端存储库中提取客户端名称。
下面是我尝试过的 "getClientName(...)" 的一些变体。我已经尝试了在 HTML 模板中调用的变体(即 promise 上的异步等)。有什么想法吗?
行为主题
public getClientName(id: string): BehaviorSubject<string> {
var result: BehaviorSubject<string> = new BehaviorSubject("");
this.clientRepo.getById(id).then(x => result.next(x.Name))
return result;
}
承诺
public async getClientName(id: string): Promise<string> {
var client: Client;
client = await this.clientRepo.getById(id).then()
var result: string = "";
if (client) {
result = client.Name;
}
return result;
}
内置的Angular async pipe 有效吗?
<clr-dg-cell>{{getClientName(clientLicense.ClientId) | async}}</clr-dg-cell>
我有一个数据网格,其中一列专门绑定到一个函数调用。
<clr-dg-column [clrDgField]="'Id'">ID</clr-dg-column>
<clr-dg-column [clrDgField]="'Client'">Client</clr-dg-column>
<clr-dg-column [clrDgField]="'Name'" [clrDgSortOrder]="ClrDatagridSortOrder.ASC">Name</clr-dg-column>
<clr-dg-column [clrDgField]="'PublicKeyHash'">Public Key Hash</clr-dg-column>
<clr-dg-row *clrDgItems="let clientLicense of ClientLicenses" [clrDgItem]="clientLicense">
<clr-dg-cell>{{clientLicense.Id}}</clr-dg-cell>
<clr-dg-cell>
{{getClientName(clientLicense.ClientId)}}
</clr-dg-cell>
<clr-dg-cell>{{clientLicense.Name}}</clr-dg-cell>
<clr-dg-cell>{{clientLicense.PublicKeyHash}}</clr-dg-cell>
</clr-dg-row>
参见第二列,我们称之为"getClientName(clientLicense.ClientId)"。该方法需要异步运行;也就是说,根据请求它不会立即具有值。我对 Typescript / Angular 有点新,但我相信我正在寻找 return Promise 或 BehaviorSubject(到目前为止,我在从我的记录中检索记录时已经广泛使用了这些通过方法调用而不是绑定/订阅存储库)。
所以,我试过 return 一个 Promise、BehaviorSubject、AsyncSubject 都得到了相同的结果——整个网络浏览器都死死锁住了,我不得不结束进程(笑)。
我知道绑定到 属性 或在我的视图模型上预填充 属性 是最简单的;但是由于体系结构,这并不容易......我基本上有两个相关的独立存储库。外键;我正在根据许可证上的客户端 ID 从客户端存储库中提取客户端名称。
下面是我尝试过的 "getClientName(...)" 的一些变体。我已经尝试了在 HTML 模板中调用的变体(即 promise 上的异步等)。有什么想法吗?
行为主题
public getClientName(id: string): BehaviorSubject<string> {
var result: BehaviorSubject<string> = new BehaviorSubject("");
this.clientRepo.getById(id).then(x => result.next(x.Name))
return result;
}
承诺
public async getClientName(id: string): Promise<string> {
var client: Client;
client = await this.clientRepo.getById(id).then()
var result: string = "";
if (client) {
result = client.Name;
}
return result;
}
内置的Angular async pipe 有效吗?
<clr-dg-cell>{{getClientName(clientLicense.ClientId) | async}}</clr-dg-cell>