これは私のコードの簡単な要約です:
var list = {
"group":{
"subgroup1":[{"name1":"Jimmy","name2":"Bob"}],
"subgroup2":[{"name1":"Sarah","name2":"Nick"},{"name1":"Kevin","name2":"George"}]
}
}
function group(group,name){
var linktothegroup;
//Note: In my actual code it will attempt to join a group before creating one this just creates a new one
//group: Specifies which subgroup to join (my actual code will check if it's valid this is just a simpler version
//name: the users name
list["group"][group].push({"name1":name,"name2":""});
linktothegroup = someway to link that group I just added; //I figured I could find the array slot and specify but that will change if a group is deleted
this.leavegroup = function(){
//leaves the group
//uses the linktothegroup var to be removed from the group
}
this.changename = function(name){
linktothegroup.name1 = name;
return true;
}
}
var cubscouts = new group("subgroup1","Billy");
cubscouts.changename("Fred");
「subgroupX」フィールドの値を編集できるようにしたいだけです (基本的には changename 関数の場合) が、常に脱退および参加するグループがあるため、変数に配列スロットを指定できません。
基本的に、ある変数を編集して別の変数を変更する方法はありますか?