{"id":13804252,"url":"https://github.com/jamesfoster/knockout.observableDictionary","last_synced_at":"2025-05-13T17:31:48.862Z","repository":{"id":2208749,"uuid":"3157781","full_name":"jamesfoster/knockout.observableDictionary","owner":"jamesfoster","description":"a comprehensive implementation of an observable dictionary in KnockoutJS","archived":false,"fork":false,"pushed_at":"2017-10-11T15:52:08.000Z","size":189,"stargazers_count":88,"open_issues_count":8,"forks_count":21,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-02T04:06:21.979Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamesfoster.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-01-11T22:06:31.000Z","updated_at":"2024-09-20T01:45:26.000Z","dependencies_parsed_at":"2022-09-11T10:51:03.297Z","dependency_job_id":null,"html_url":"https://github.com/jamesfoster/knockout.observableDictionary","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesfoster%2Fknockout.observableDictionary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesfoster%2Fknockout.observableDictionary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesfoster%2Fknockout.observableDictionary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesfoster%2Fknockout.observableDictionary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamesfoster","download_url":"https://codeload.github.com/jamesfoster/knockout.observableDictionary/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225247851,"owners_count":17444124,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T01:00:44.519Z","updated_at":"2024-11-18T20:31:42.735Z","avatar_url":"https://github.com/jamesfoster.png","language":"JavaScript","readme":"To use the knockout observable dictionary you simply need to reference knockout and then this\r\n\r\n    \u003cscript type='text/javascript' src=\"http://github.com/downloads/SteveSanderson/knockout/knockout-2.0.0.js\"\u003e\u003c/script\u003e\r\n    \u003cscript type='text/javascript' src=\"https://raw.github.com/jamesfoster/knockout.observableDictionary/master/ko.observableDictionary.js\"\u003e\u003c/script\u003e\r\n\r\nThen pass a javascript object to ko.observableDictionary() as follows.\r\n\r\n    var person = {\r\n        name: 'Joe Bloggs',\r\n        height: 180,\r\n        'hair colour': 'brown'\r\n    };\r\n    \r\n    var viewModel = {\r\n        person: new ko.observableDictionary(person)\r\n    };\r\n    \r\n    ko.applyBindings(viewModel);\r\n\r\nTo loop over the items in the dictionary simply data bind to the items property. Each item has a `key` property and a `value` property\r\n\r\n    \u003cul data-bind=\"foreach: person.items\"\u003e\r\n        \u003cli\u003e\r\n            \u003cspan data-bind=\"key\"\u003e\u003c/span\u003e\r\n            \u003cspan data-bind=\"value\"\u003e\u003c/span\u003e\r\n        \u003c/li\u003e\r\n    \u003c/ul\u003e\r\n\r\nYou can also data bind to specific elements within the dictionary using the method `get`\r\n\r\n    \u003clabel\u003eName: \u003cinput data-bind=\"person.get('name')\" /\u003e\u003c/label\u003e\r\n\r\nYou can even data bind to elements which don't exist yet. In this case, if you update the value it will add a new item to the dictionary.\r\n\r\n    \u003clabel\u003eCompany: \u003cinput data-bind=\"person.get('company')\" /\u003e\u003c/label\u003e\r\n\r\nTo set a value on the dictionary in code use either:\r\n\r\n* the `set` method: `viewModel.person.set('hair colour', 'blue');`. or\r\n* the `get` method: `viewModel.person.get('hair colour')('blue');`.\r\n\r\n\r\nThe obersvableArray methods `indexOf`, `remove`, `sort` and `push` have also been overridden to behave as expected with dictionaries e.g. `viewModel.person.remove('height')` and `viewModel.person.indexOf('hair colour')`\r\n\r\nEnjoy\r\n\r\n    ","funding_links":[],"categories":["Plugins and libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesfoster%2Fknockout.observableDictionary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamesfoster%2Fknockout.observableDictionary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesfoster%2Fknockout.observableDictionary/lists"}