:dict
type descscription >= 1.0.0
:dict
it used to get an item from an array data, in the Nodejs environment and browser, there are some difference with where to get an array data。
In Nodejs
&
in Nodejs environment, you need set a pathdata attribute
, the path pointed to a dict file。
/**
* Such as in your data directory <dataDir>
* There's a dictionary file named 'dict.txt'
* It have many items like this:
* ---------------
* hello
* world
* ---------------
*/
const instance = Such.instance(":dict:&<dataDir>/dict.txt");
instance.a(); // `hello`
instance.a(); // `hello`
instance.a(); // `world`
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
In browser
#[data=]
in browser, you need set a configurationdata attribute
, set adata
field key, and set the value as a variable name what injected by the APISuch.assign
.
// Assign a `dict` variable data
Such.assign("dict", ["hello", "world"]);
// Use the `dict` variable as the `:dict`'s data field value
const instance = Such.instance(":dict:#[data=dict]");
instance.a(); // `hello`
instance.a(); // `hello`
instance.a(); // `world`
1
2
3
4
5
6
7
2
3
4
5
6
7