Angularjs manipulate key-value objects similar to Java HashMap (landfills summary) _angularjs

Source: Internet
Author: User

Objective:

We know that the most used Java HashMap is put (...), get (...) and the Remove () method, how do you create (use) such an object in Angularjs?

Thinking Analysis:

We know that in Java you can use chained access and "[]" to access one of the values of HashMap

Specific implementation:

Chained access:

. 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;}}
)

"" "Access:

. Factory (' Iparamsservices ', function () {
var map = {};
return {
get:function (key) {return
Map[key];
},
put:function (Key, object) {
Map[key] = Obje CT;
},
remove:function (key) {
delete map[key];}}
)

4. Verify

1. Write

Paramsservices.put ("ITV", "ITV");
Paramsservices.put ("ITV2", "ITV2");
Iparamsservices.put ("ITV3", "ITV3");

2. Read

Paramsservices.get ("ITV") = = Paramsservices.get ("ITV2")//True
iparamsservices.get ("itv3") = = Iparamsservices.get ("ITV4")//False

5. Summary:

Angul as a key value object (HASHMAP) recommended by the way to implement

The above is a small set to introduce the ANGULARJS operation of the key value object similar to Java HashMap (landfills summary), I hope to help you, if you have any questions welcome to my message.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.