Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter issue with certain keys #211

Closed
Serbitas opened this issue Jun 12, 2017 · 1 comment · Fixed by #231
Closed

filter issue with certain keys #211

Serbitas opened this issue Jun 12, 2017 · 1 comment · Fixed by #231

Comments

@Serbitas
Copy link

Keys with a dot do not work with filtering.

require(["dstore/Memory"],
            function(Memory){
                var employees = [
                    {name:"Jim", "dep.artment":"accounting"},
                    {name:"Bill", "dep.artment":"engineering"},
                    {name:"Mike", "dep.artment":"sales"},
                    {name:"John", "dep.artment":"sales"}
                ];
                employeeStore = new Memory({data:employees, idProperty: "name"});
                employeeStore.filter({"dep.artment":"sales"}).forEach(function(employee){
                    // this is called for each employee in the sales department
                    alert(employee.name);
                });
            });
@msssk
Copy link
Contributor

msssk commented Jan 16, 2020

This is by design to enable shorthand query syntax for nested properties. The filter employeeStore.filter({ 'dep.artment': 'sales' }) would work with the data:

var employees = [
	{ name: "Jim", dep: { artment: "accounting" } },
	{ name: "Bill", dep: { artment: "engineering" } },
	{ name: "Mike", dep: { artment: "sales" } },
	{ name: "John", dep: { artment: "sales" } }
];

If you need to handle property names that contain a period, you'll have to provide a custom _createFilterQuerier implementation. For a full reference implementation look in dstore/SimpleQuery.

The code below, which is an incomplete implementation not suited for use, demonstrates how to handle the specific case in this issue:

_createFilterQuerier (filter) {
	return function (data) {
		return data.filter(function (item) {
			return item[filter.args[0]] === filter.args[1];
		});
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants