Ticket #121 (closed enhancement: fixed)
client side forms framework: URI Templates
| Reported by: | karel | Owned by: | mpo |
|---|---|---|---|
| Priority: | minor | Milestone: | 0.3 |
| Component: | -- unknown -- | Version: | trunk |
| Keywords: | uritemplate forms | Cc: |
Description (last modified by karel) (diff)
Feature request for the URI Template functionality (in the client-side forms framework):
dot-separated template parts should be treated as nested object structures:
Current behaviour:
var t = new kp.Template("/test/{foo.id}");
t.expand({"foo": { "id": 5 }}); -> returns "/test/" instead of the more useful "/test/5"
t.expand({"foo.id": 5}); -> returns "/test/5" (which explains why the above does not work)
Suggested behaviour:
t.expand({"foo": { "id": 5}}); -> returns "/test/5";
To find the literal "foo.id" property, you should escape the dot in the template:
var t = new kp.template("/test/{foo\\.id}");
t.expand({"foo.id": 5}); -> returns "/test/5"
Change History
comment:2 Changed 5 years ago by mpo
Implemented in revision [766]
I did not opt for the \. escape notation but choose the more classic js ["property-name"].
Notes:
- Codewise this made it trivial to also support arrays, and the full range of ['xyz'] ["abc"] [123] next to sub.property.
- Additionally the routine works recursively to support any sub-sub combination of the above.
- For reasons of backwards compatibility, enforced though samples from the uri-template spec that we supported before we still support a uri-template {z.z} by first looking for context["z.z"] and only if not found for context.z.z
- An initial implementation through eval() was considered potentially harmful.
- Calling functions on context-objects was already supported before by just referencing the function-name without the (). Passing arguments to those functions, or further indexing the returned resulting object is (still) NOT supported.
Note: See
TracTickets for help on using
tickets.