-
Notifications
You must be signed in to change notification settings - Fork 69
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
Allow definition of nested model relationships with dotted notation #91
base: master
Are you sure you want to change the base?
Conversation
Allow definition of nested model relationships with dotted notation: obj.model.set({person:{name:'John Doe'}}) can now be addressed with 'person.name' in data bindings as well as obj.model.get('person.name') Events are also specified with dotted notation 'change:person.name':function(){}
if (typeof arg === 'string') { | ||
return this.model._data[arg]; | ||
if (typeof arg === 'string') { | ||
var paths = arg.split('.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, we seem to have some indentation issues here - perhaps you're using tabs and not spaces? we use spaces in Agility
This looks good to me, really like those tests. @tristanls ? |
@@ -343,6 +343,37 @@ | |||
this.model._data = $.extend({}, arg); // erases previous model attributes without pointing to object | |||
} | |||
else { | |||
//iterate through properties and find nested declarations | |||
for (var prop in arg){ | |||
if (prop.indexOf('.') > -1){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems that this would allow setting a property referenced by an empty string:
data-bind=".oops"
which will try to generate a structure of:
model._data[ '' ] = { oops : 'value' };
This is not a bad thing in itself, and perhaps some future convention can have special meaning for variables ".myFoo" as a result of that, just thinking out loud here.
Made a note on code and I'm rusty getting back to ui development, but taking a quick look nothing breaking jumped out. |
What about 'person.addresses.0.street', 'person.addresses.1.street' ? PS: I'm just starting with Agilityjs. I've tested Backbonejs, Knockoutjs, Angularjs, Emberjs, but Agilityjs is the one that fits my way of programming the best. It's really a clever piece of code, thanks Artur. I hope that you will find more time to take care of it. |
Allow definition of nested model relationships with dotted notation:
obj.model.set({person:{name:'John Doe'}})
can now be addressed with 'person.name' in data bindings as well as
obj.model.get('person.name')
Events are also specified with dotted notation
'change:person.name':function(){}