Home > front end >  How to define a dynamic properties?
How to define a dynamic properties?

Time:11-13


I have so a set of data, including table_1, table_2 is dynamic, and will continue to increase table_3
I want to get to the data in the table_1 is no problem, at ordinary times for the setting of the data that can be
Table. Cache. Table_1 [0]. Name='zhang'
Problem is table_1 [0] this is dynamic, I couldn't set values make him joining together after
Var arr={};
Arr. Name='table_1 [0]'.
Table. Cache. Arr. Name. Name='* *'; This is an error, have what way?
Table. Cache. Table_1 [0]. Name='zhang' so that you can

CodePudding user response:

I don't know what you said table_1 [0] how is the so-called "dynamic" dynamic???????

 table. Cache. Table_1 [0]. Name='* *';//this is the most direct way of assignment 


//can also use attribute access way 
Const propName='name'
Table. Cache. Table_1 [0] [propName]='* *';


But if your so-called "dynamic", which is similar to
 
Const a={
B: {
C: {
D: {1} e:
}
}
}


And then you because of the so-called "dynamic" direct assignment cannot use the following way:
 A.B.C.D.E=2; 


But hope to have a method can directly read and write to the specified path, such as:
For a, path: assignment B.C.D.E for operation, may be you can be imagined like this:
 a [' B.C.D.E]=2; 


But, in fact, this is no good, you need to write their own methods to implement it,


If you say "dynamic" is not in the list, post your code, not to describe, in your side "imagine" only you know what, but I do not write the

CodePudding user response:

If two-way binding directly modify values,
If not two-way binding will be revised the assignment again

CodePudding user response:

 
Var a={
Cache: {
Table_1: [
{name: 'aaa'}
],
Table_2: [
{
Name: 'BBB'
},
{
Name: 'bbb1'
}
]
}
}

Var b={
Name: 'table_1',//table_1 object
Index: 0//table_1 subscript
}
Var c={
Name: 'table_2'
Index: 1
}
The console. The log (a.c ache [b.n ame] [b.i ndex]. Name)
The console. The log (a.c ache [c.n ame] [c.i ndex]. Name)

CodePudding user response:

Learn to use the eval
 var ta={name: "this is the value of ta."}; 
Var arr={name: "ta. The name"};
The console. The log (arr. Name);//print arr name
The console. The log (eval (arr. Name));//print ta name

  • Related