【问题标题】:Property of class exists but undefined类的属性存在但未定义
【发布时间】:2018-12-13 06:32:55
【问题描述】:

当我点击行时,我有一个收集数据的功能,我将数据保存在对象中。当我记录对象时,它返回对象类型。但是当我尝试记录它的属性时,它是未定义的。

branchToDivision: BranchDto;
    onSelect(record: BranchDto) {

        this.branchToDivision = record;
        console.log(this.branchToDivision);
        console.log(this.branchToDivision.brancH_CODE);

    }

console screen

GetBranchForView {branch: BranchDto}

未定义

我不知道是什么问题。

Here is Object definition

Console display

【问题讨论】:

  • 如果您在控制台中展开“GetBranchForView”...您会看到属性...您在那里看到“branchH_CODE”吗?
  • 我能看一下对象的定义吗?如果是的话,你填充对象的代码。
  • @AIqbalRaj 在控制台中,brancH_CODE 显示有值。
  • 你能分享一下控制台的截图吗...也许有什么东西不让你...
  • 你可以试试this.branchToDivision = record.branch;吗?

标签: javascript angular6


【解决方案1】:

这对你有用吗?

console.log(this.branchToDivision.branch.brancH_CODE);

【讨论】:

  • 我收到一条消息,提示您“BranchDto 类型上不存在属性分支”。我稍微改变了我的功能。 onSelect(record: any) { this.branchToDivision = record; console.log(record.branch.branchH_CODE);我可以得到价值。但我想按对象传递数据
  • 当你这样做时。branchToDivision = record; ...对象被复制到this.branchToDivision ...你可以试试this.branchToDivision = JSON.parse(record);然后是 console.log(this.branchToDivision.branch.branchH_CODE); ...
  • 嗨@AIqbalRaj,我还是不能让它工作,我可以联系你寻求解决方案吗?
  • 确定,你想怎么连接?
  • Skype 或 Facebook 视频通话更适合您?
【解决方案2】:

我找到了答案。数据表上的每一行都由一个名为 GetBranchForView 的类表示。所以当我试图捕捉事件时,我必须传递一个 GetBranchForView 类型的参数。这对我有用。

onSelect(record: GetBranchForView) {
        this.item = record;
        this.branchToDivision = record.branch;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-01
    相关资源
    最近更新 更多