标签:factor put pre 实现 hash delete 如何 方法 方式
.factory(‘ParamsServices‘, function () { var params = {}; return { get: function (key) { return params.key; }, put: function (key, object) { params.key = object; }, remove: function (key) { delete params.key; } }; })
.factory(‘iParamsServices‘, function () { var map = {}; return { get: function (key) { return map[key]; }, put: function (key, object) { map[key] = object; }, remove: function (key) { delete map[key]; } }; })
4.验证 1.写入 ParamsServices.put("itv", "itv"); ParamsServices.put("itv2", "itv2"); iParamsServices.put("itv3", "itv3"); iParamsServices.put("itv4", "itv4"); 2.读取 ParamsServices.get("itv") == ParamsServices.get("itv2") // true iParamsServices.get("itv3") == iParamsServices.get("itv4") // false
5.总结: angularJS操作键值对象(hashmap)建议采用方式二来实现
6.分享和交流: 如有纰漏,望各位看客斧正,谢谢
angularJS操作键值对象(类似java的hashmap)填坑小结
标签:factor put pre 实现 hash delete 如何 方法 方式
原文地址:http://www.cnblogs.com/imaikce/p/6055843.html