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; ...
随机推荐
- 【linux】crontab定时命令
参考来源: http://blog.csdn.net/ariessurfer/article/details/7459183 http://www.jb51.net/LINUXjishu/19905. ...
- Django视图之ORM数据库查询操作API
查询表记录 查询相关API 操作:models.表名.objects.方法() all(): 查询所有结果 filter(**kwargs): 它包含了与所给筛选条件相匹配的对象 get(**kwar ...
- DataSet、DataTable、DataRow的数据复制方法
DataSet 对象是支持 ADO.NET的断开式.分布式数据方案的核心对象 ,用途非常广泛.我们很多时候需要使用其中的数据,比如取得一个DataTable的数据或者复制另一个DataTabe中的数据 ...
- 微信小程序实战篇-下拉刷新与加载更多
下拉刷新 实现下拉刷新目前能想到的有两种方式 1. 调用系统的API,系统有提供下拉刷新的API接口 2. 监听scroll-view,自定义下拉刷新,还记得scroll-view里面有一个binds ...
- Palindrome Partitioning——回溯算法的又一经典
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- MySQL 的数据存储引擎
MySQL的存储引擎 InnoDB: MySQL5.5之后的默认存储引擎. 采用MVCC来支持高并发,并且实现了四个标准的隔离级别(默认可重复读). 支持事务,支持外键.支持行锁.非锁定读(默认读取操 ...
- TCP握手协议简述
TCP握手协议简述在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接.第一次握手:建立连接时,客户端发送syn包(syn=j)到服务器,并进入SYN_SEND状态,等待服务器 ...
- [thinkphp] 无限极分类
<?php /* * 无限极分类 类 */ header("Content-Type: text/html; charset=UTF-8"); Class Category ...
- ExtJs之组件(window)
Ext.create('Ext.window.Window',{ title:'', width:400, height:300, constrain:true,//限制窗口不 ...
- C++中template的.h文件和.cpp文件的问题
在C++中,用到类模板时,如果类似一般的类声明定义一样,把类声明放在.h文件中,而具体的函数定义放在.cpp文件中的话,会发现编译器会报错.如类似下面代码: //test.h文件 #ifndef TE ...