Can't access object property, even though it shows up in a console log

后端 未结 30 1773
日久生厌
日久生厌 2020-11-22 06:26

Below, you can see the output from these two logs. The first clearly shows the full object with the property I\'m trying to access, but on the very next line of code, I can\

30条回答
  •  礼貌的吻别
    2020-11-22 07:13

    I had similar problem (when developing for SugarCRM), where I start with:

    var leadBean = app.data.createBean('Leads', {id: this.model.attributes.parent_id});
    
    // This should load object with attributes 
    leadBean.fetch();
    
    // Here were my attributes filled in with proper values including name
    console.log(leadBean);
    
    // Printed "undefined"
    console.log(leadBean.attributes.name);
    

    Problem was in fetch(), its async call so I had to rewrite my code into:

    var leadBean = app.data.createBean('Leads', {id: this.model.attributes.parent_id});
    
    // This should load object with attributes 
    leadBean.fetch({
        success: function (lead) {
            // Printed my value correctly
            console.log(lead.attributes.name);
        }
    });
    

提交回复
热议问题