开发者

JAVASCRIPT: data structure instead of arrays

I'm building a form where a description field changes it's content based on the input (onchange event) of the form. I have multiple input fields and each have their开发者_开发问答 own description.

What I have been doing in the past is for each field (this is a very small examle):

var wisdom  = [' ', 'Seeker of Wisdom', 'Collector of Wisdom', 'Devotee of Wisdom', 'Devourer of Wisdom', 'Font of Wisdom', 'Oracle of Wisdom', 'Source of Wisdom'];
var wisdomp = [0, 100, 250, 550, 1200, 2500, 5000, 10000, 10000];

But initializing all these vars on the page doesn't seem right to me and creates a huge block of text. That's why I thought it would be better to read this data from an external file. I couldn't find a javascript file reader though.

Is there any better structure or method to keep and retrieve data using javascript?


in fact, you can use json to describe a k/v structure that seems to match your need:

{' ':0,'Seeker of Wisdom':100,'Collector of Wisdom':250 } and so on

note that you can also use nested structures as well using this notation.

see: http://www.json.org


jQuery create select list options from JSON, not happening as advertised? is more popular alternative to mentioned problem. would not bet on it being any better

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜