javascript 如何访问一个对象并迭代它以显示一个表

ia2d9nvy  于 2022-11-27  发布在  Java
关注(0)|答案(1)|浏览(132)

我无法访问lstTest,它在console.log(response_testQ.lstTest);中显示为未定义,但奇怪的是,当我输入console.log(response_testQ);时,lstTest显示为Array(3)

如何使用forEach(...)在lstTest内部进行迭代?

export class testQ {
    lstTest?: Test[];
}

export class Test {
     TestId?: number;
}
  • 这是我执行的函数 *
Test.SelectAllPaged(request_testQ).subscribe(
    {
        next: newrow => {
            const response_testQ = newrow.response as testQ;
            var TableContent: string = "";

            console.log(response_testQ);
            console.log(response_testQ.lstTest);

            response_testQ?.lstTest?.forEach(d => { //HERE IT DOESN'T ENTER
                TableContent += `<tr>
                    <td>
                        <div class="custom-control">
                            <input id="Test${d.TestId}" type="checkbox">
                        </div>
                    </td>
                </tr>`;
            })
            },
            complete: () => {
                $(window).on("scroll", ScrollDownNSearch);
                console.log("Search finished");
            },
            error: err => {
                console.log("Error during server call. No internet connection?", err)
            }
        });
llmtgqce

llmtgqce1#

问题是response_testQ给我的是lstTestModel而不是lstTest

相关问题