JavaScript Dictionary
Excellent. The 4guysfromrolla example is very helpful, thanks. I've pasted a complete javascript.js file below which allows one to create a dictionary to make calls like the following:
var userDict = new Dictionary();
userDict.Add("smith", "admin");
userDict.Add("jones", "user");
userDict.Delete("jones");
var keys = userDict.Keys
for(var i=0; i<keys.length; i++)
{
alert((keys[i]+": "+userDict.Lookup(keys[i])));
}
Admittedly, the keys array is inefficient, but it's very handy in situations where the dictionary is small.
--Brett
//===========================================================================// Provides a Dictionary object for client-side java scripts//===========================================================================functionLookup(key){return(this[key]);}functionDelete(){for(c=0; c <Delete.arguments.length; c++){this[Delete.arguments[c]]=null;}// Adjust the keys (not terribly efficient)var keys =newArray()for(var i=0; i<this.Keys.length; i++){if(this[this.Keys[i]]!=null)
keys[keys.length]=this.Keys[i];}this.Keys= keys;}functionAdd(){for(c=0; c <Add.arguments.length; c+=2){// Add the propertythis[Add.arguments[c]]=Add.arguments[c+1];// And add it to the keys arraythis.Keys[this.Keys.length]=Add.arguments[c];}}functionDictionary(){this.Add=Add;this.Lookup=Lookup;this.Delete=Delete;this.Keys=newArray();}
JavaScript Dictionary的更多相关文章
- javascript Dictionary data structures
Dictionary常被称为数据字典,是一种用来保存键值对的数据结构,比如我们日常的电话本,就是一个Dictionary.我们通过键(名字),就可以访问到对应的值(电话号码).在C++与java中我们 ...
- Hash - a javascript dictionary object.
Hash,in wikipedia, may relevant to many stuffs. In javascript, hash is a group of name/value pairs w ...
- Passing JavaScript Objects to Managed Code
Silverlight If the target managed property or input parameter is strongly typed (that is, not typed ...
- Search API 官方文档 可以用了查看自己的app
Search API October 24, 2012 - HTTPS is now supported for Search and Lookup requests. Please update y ...
- JavaScript基础精华03(String对象,Array对象,循环遍历数组,JS中的Dictionary,Array的简化声明)
String对象(*) length属性:获取字符串的字符个数.(无论中文字符还是英文字符都算1个字符.) charAt(index)方法:获取指定索引位置的字符.(索引从0开始) indexOf(‘ ...
- JavaScript中创建字典对象(dictionary)实例
这篇文章主要介绍了JavaScript中创建字典对象(dictionary)实例,本文直接给出了实现的源码,并给出了使用示例,需要的朋友可以参考下 对于JavaScript来说,其自身的Array对象 ...
- javascript字典数据结构Dictionary实现
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&qu ...
- JavaScript 字典(Dictionary)
TypeScript方式实现源码 // set(key,value):向字典中添加新元素. // remove(key):通过使用键值来从字典中移除键值对应的数据值. // has(key ...
- JavaScript 模拟 Dictionary
function Dictionary() { var items = {}; //判断是否包含Key值 this.has = function(key) { return key in items; ...
随机推荐
- Mybatis学习—XML配置文件
总结自 Mybatis官方中文文档 XML 映射配置文件 MyBatis 的配置文件包含了会深深影响 MyBatis 行为的设置(settings)和属性(properties)信息.文档的顶层结构如 ...
- EL表达式使用时出现NumberFormatException异常
从后端数据库取出书本集合,然后循环输出到前端表格: <c:forEach items="${bookManagedBean.bookList}" var="book ...
- hdu 1547(BFS)
Bubble Shooter Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- [前端随笔][CSS] 制作一个加载动画 即帖即用
说在前面 描述 [加载中loading...] 的动画图片往往使用GIF来实现,但GIF消耗资源较大,所以使用CSS直接制作更优. 效果传送门1 效果传送门2 关键代码 @keyframes 规则 用 ...
- 【Mac电脑】Jenkins的安装
1.JDK自己下载安装喽, 2.下载Jenkins 下载路径:https://mirrors.tuna.tsinghua.edu.cn/jenkins/war-stable/2.121.1/jenki ...
- HRBUST 1217 统计单词个数
$dp$. 设$dp[i][j]$为到$i$位置,切成了$j$段的最大收益,然后枚举一下$f$,$dp[i][j]=max(dp[f][j-1]+v[f+1][i])$.一段区间的价值可以用区间$dp ...
- go chapter 6 - map array
遍历 for i,v := range *arr { // 遍历数组,第一个参数为index, 第二个参数为元素 fmt.Println("---------------") fm ...
- java 日期validate
public static boolean isValidDate(String str) { boolean convertSuccess=true; // 指定日期格式为四位年/两位月份/两位日期 ...
- POJ - 1835 宇航员(模拟题)
问题描述: 宇航员在太空中迷失了方向,在他的起始位置现在建立一个虚拟xyz坐标系,称为绝对坐标系,宇航员正面的方向为x轴正方向,头顶方向为z轴正方向,则宇航员的初始状态如下图所示: 现对六个方向分别标 ...
- 【DFS】Paintball(6-22)
[UVA11853]Paintball 算法入门经典第6章6-22(P175) 题目大意:有一个1000*1000的正方形战场,西南角坐标(0,0),西北角坐标(0,1000),有n个敌人,每个敌人处 ...