javascript - Best format of localStorage -
i have array of object tree
var tree = [{ "id": "1", "name": "one", "child": [], }, { "id": "2", "name": "two", "child": [{ "id": "21", "name": "twentyone", "child": [], },{ "id": "22", "name": "twentytwo", "child": [], }], }, {{ "id": "3", "name": "three", "child": [], }, }].
which 1 best way store array of objects in localstorage
? better use format?
there several methods:
- getitem
- getallitem
- removeitem
- saveitem
but there child arrays of objects. means use recursive search find necessary object.
save data in localstorage array, or array of simple objects, try keep dry (don't repeat yourself). example, if have list of people, keep array of people, don't keep separate variable count.
what want "state". long keep minimal fine. can use lodash or underscore find, merge, add, remove elements array.
Comments
Post a Comment