-
Notifications
You must be signed in to change notification settings - Fork 11
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
Collection: find #5
Comments
I think you have misunderstood how this works, [User.name] isnt a valid selector for your data, you only have 2 attributes, id and name, you are picking all models that has the "User.name" attribute set, console.log(collection, collection.find("[name]")); will get all models with the name attribute, which is what you want. console.log(collection, collection.find("[name=Bob]")); will return only the first entry |
Hi, |
yes, basically, you have an object that notates as `User.name' whereas the simple property selector is for properties at the level of User. you can do a custom property getter 'name' in your model prototype that returns user.name or you can do var myCollection = new Class({
Extends: Epitome.Collection,
findByName: function(who) {
return this.filter(function(model){
return model.get('User').name == who;
});
}
});
var collection = new myCollection([{
User: {name: 'Bob', id: 2}
},
{
User: {name: 'Angry Bob', id: 3}
}
]);
console.log(collection.findByName('Bob')); I like the idea of being able to search deep object properties but the problem is, there is no guarantee that what people put in the model is just a plain / primitive property and not a function or a Class or whatever. Also, the . notation is just sugar. for example, if you did:
this may make sense from your data standpoint as you want your json to actually send If there can be a rule to be defined here as to how to serialize the model and to apply a deep obj property searach, i would be very happy to do so. mootools/mootools-core#2191 was a similar sort of thing which allowed you to do:
it did not get pulled into mootools-core. it may end up at mootools-more. it would probably be trivial to extend the selector engine to do that so its like |
ok thanks, i'll wait for this. |
…eg. .find("User[name=Bob]")
it's not ready yet, though in your case it seems to work. got some issues I need to fix but working on it. expectation for .find('User') being the same as .find('[User]') is not passing yet. will commit more today or tomorrow. |
seems to now work - in the branch |
Hi, this works great. Thanks ! |
var collection = new Epitome.Collection([
{
User: {name: 'Bob', id: 2}
},
{
User: {name: 'Angry Bob', id: 3}
}
]);
console.log(collection, collection.find('[User.name]'));
This actually doesn't work :( I am retrieving datas from CakePhp.
The text was updated successfully, but these errors were encountered: