0
@track defaultRecordWith4Field = {
        recId : 0,
        fieldList : [
            {
                name:"description__c",
                value :null
            },{

                name:"type__c",
                value :null
            },{
                name:"property__c",
                value :null

            },{
                name:"Direction_property__c",
                value :null

            }
        ]
    };

I'm trying to modifying recId in the object declared above to add one more row I'm not getting how to do that

Trying to add new value to "recId"

handleAdd(){
        console.log(object.key(this.defaultRecordWith4Field));
        this.defaultRecordWith4Field.recId=this.records.length++;// I'm trying here
        var newRecord = Object.assign({}, this.defaultRecordWith4Field);
        this.records.push(newRecord); 
        console.log("this.records : " + JSON.stringify(this.records));
    }

1 Answer 1

0
    this.defaultRecordWith4Field.recId=this.records.length++;// I'm trying here

The x++ operator returns a variable value, then increases it by 1 (you can also ++x, which increases by 1, then returns the newly increased variable value). In JavaScript, this actually increases the associated array's size by one (a new null entry is added at the end).

What you probably meant to do is to add 1 to the value:

    this.defaultRecordWith4Field.recId=this.records.length+1;

Which does not modify the variable being used.

1
  • When I try to access the variable like this.defaultRecordWith4Field.recId it says This page has an error. You might just need to refresh it. [Cannot read property 'recId' of undefined] Failing descriptor: {markup://c:pointofInterestInputForm}
    – Ravi Kumar
    Commented Apr 26, 2021 at 15:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .