I'm hoping you can help me with this question as I'm somewhat of a novice when it comes to javaScript.
My goal is to create an object, and have checkboxes be able to update the properties of this object based on whether they are checked or not. I can get the object to be updated within the "change" listener function for an individual checkbox, but I want to be able to pass that updated object back into other checkbox listener functions.
Basically, I'd like to pass around that 'tenant' object (whose default will have 'status' set to 'true')to multiple checkbox listeners which can update the object. So I guess my question is how to get the updated object to be accessible outside of the checkbox function. Code below. Thanks in advance!
//Build 'tenant' object
var tenantObject = {
"Tenants": [{
"Name": "WeWork",
"Status": true
}, {
"Name": "Regus",
"Status": true
}
]
}
console.log(tenantObject)//Status is 'true'
//Tenant Checkboxes
d3.selectAll("#WeWorkCheckbox").on("change", function() {
var type = "WeWork"
display = this.checked ? "inline" : "none";
statusCheck = this.checked ? true : false
if (statusCheck == false) {
tenantObject.Tenants[0].Status = false
console.log(tenantObject.Tenants)// This works - the WeWork item now reads 'false'
return tenantObject.Tenants
}
});
console.log(tenantObject)//Status still reads 'true' for WeWork, I want this to reflect the update in the above function
Aucun commentaire:
Enregistrer un commentaire