Uppercase field is not bound properly in template
This is more for reference for others as a real question, since I guess I
have already understood what is going on. But it took a while, so I will
document it here.
In one of my models, I have a field named VAT. I try to bind to this field
in an template:
{{view Ember.TextField valueBinding="VAT" id="VAT-id" placeholder="VAT"
required="true"}}
But this is not working, which was kind of surprising, and took some time
to understand.
Some questions:
Is this a limitation of Ember or ember-data? (I guess ember-data?)
How is an uppercase field name translated by ember? There is a section in
the documentation describing how the REST adapter transforms underscored
attributes, but nothing regarding uppercase fields.
What can I do to refer to this field using the real name? (I guess it is
not possible?)
The only workaround I know is to do:
App.Adapter.map('App.Company', {
...
vat : {key: 'VAT'},
});
which still does not allow to use the real name in the templates; I must
still use vat (in lowercase). I guess it is really not possible to use the
original uppercase field name using ember-data?
NOTE
Oh, and don't forget that the REST adapter must be created after it has
been fully configured, otherwise the configuration is not used. This has
been a source of much confusion too. So do it like this:
App.Adapter = DS.RESTAdapter.extend({ ... });
App.Adapter.configure('plurals', { ... });
App.Adapter.map('App.Company', { ... });
... more adapter configuration
And now you can do:
App.Store = DS.Store.extend({
revision: 13,
adapter: App.Adapter.create(),
...
});
If you invert the order, Ember will not say anything, but the
configuration will not be active.
No comments:
Post a Comment