简体   繁体   中英

Store data structured without database in javascript

don't be deterred of the long snippets, for some of you guys, i think, it is quietly easy.

hope the headline says the main message of my question. What I am trying to do is to structure a amount of key:value in combination with objects and arrays pairs.

Information

  • Its for easier templating with EJS to have the whole html elements in a config.
  • The config contains about 30 items
  • These are completely logic questions, also for further developing
  • I wouldn't use a database for this
  • It should be dynamic and extendable

Example

var items = {
    basic: {
        someKey: [
            {
                id: 'title',
                title: 'Title', 
                type: 'text', ...
            }, ...
        ], ...
    }, ...
}

After defining those things (need them later for single operations) i try to get in a structure so i can make it a bit more easier for later use.

var sections = [
    {
        title: 'Basic',
        rows: [{
            columns: [
                { title: 'Default', items: items.basic.someKey }, ...
            ]
        }]
    }, ...
]

some kind of output would be like this:

<input type="<%= item.type %>" id="<%= item.id %>" value="<%= item.value %>" placeholder="<%= item.ph %>">
  • How would you do those things ?
  • Is there a better solution for this ?
  • Is the way to store it in javascript better than parse them from xml or somewhat ?

I think you might want to check out JSON . Plenty of libraries for parsing and generating it, and it's based on a subset of JavaScript so you shouldn't have to change your syntax too much if at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM