Angular 根据表单中的值在用户屏幕上显示数据



>我必须通过应用某些条件,根据通过单选按钮接收的输入在屏幕上显示数据。当从单选按钮中选择 name 属性时,我还需要帮助获取对象的 id。 这是我用所有基本数组和表单创建的堆栈闪电战,并在 .ts 文件的注释中描述了我需要的内容。我试图使代码尽可能干净,切中要害。请问我更多关于这一点的澄清。谢谢。

我不知道你是否看到我做了什么(我不知道 Stackblitz 究竟是如何工作的(,但是

添加

const o = this.dummyData.find(x => x.hiringTypeId == this.mergeObj.hiringTypeId && x.processName == this.mergeObj.processName);
if (o) {
this.mergeObj.processId = o.processId;
}
// NOW ProcessId is set (if found)
console.log("mergedObject",this.mergeObj)

在第 61 行(并将: any类型添加到 mergeObj(为您提供相应的对象

if (o)块中,您甚至可以使用o.data[0].name来检索showName字段

和平

我无法分叉堆栈闪电战

我已经尝试过使用该代码

请将您的添加过滤器功能更改为

addFilter(filter: NgForm) {
Object.assign(this.mergeObj, filter.value);
console.log("ss");
this.finalArray = this.dummyData.filter(a => {
return (
(filter.value.processName == null ||
filter.value.processName == undefined ||
filter.value.processName == a.processName) &&
(filter.value.hiringTypeId == null ||
filter.value.hiringTypeId == undefined ||
filter.value.hiringTypeId == a.hiringTypeId)
);
});

filter.reset();
console.log("mergedObject", this.mergeObj);
//Add code here
//Important : right now the mergedObj is giving me the processName and hiringTypeId. I want the mergeObj to give me the processId along with the processName and hiringTypeId. {processName : "selectedValue",processId : "selectedValue", hiringTypeId : "selectedValue"}
}

你会得到结果到最终数组

在您的 HTML 中从第 25 行到 .....

<div style="border:1px solid green">
<!-- <span>Show Data under this or legit anywhere, I have exhausted my every last motivated cell.HELP ME in the name of Baby Yoda</span> -->
<div *ngFor="let data of finalArray">
<div>processName : {{data.processName}}</div>
<div>processId : {{data.processId}}</div>
<div>hiringTypeId : {{data.hiringTypeId}}</div>
<div>{{data.data | json}}</div>
</div>
</div>

注意:在这里我使用了过滤器函数,它将过滤您从服务器端获取的 dummayarray 中的数据,但如果您只想获取一个对象,则可以使用 find 方法,它将只返回一个 obj

如果您需要其他任何东西,请告诉我。

谢谢

最新更新