Comments (11)
I don't like this one, reason is that it requires a transformation of the typical json that you receive from rest. What about the following:
data-bind, name, id for the default one
and data-bind-href, data-bind-src, etc for specific overrides. Using this approach it is possible to have flat json input and map that directly to the markup without any transform.
from plates.
My apologies, I should have used gist for the code, here is a sample of attribute binding, where data-attributeName is used to map JSON to attributes, no modification to the JSON data is necessary.
https://gist.github.com/1364192
from plates.
Ha funny, seems we had almost an identical idea :).
I do think though that it needs to always start with data-bind- otherwise you would end up interfering with existing html that uses data- to drive javascript functionality.
from plates.
good point, do you have a link where data- is used to drive js functionality?
from plates.
Don't have a link for that, but I have seen it in the wild and use it myself. For example I some where use it like this:
This of course has huge benefits, you are really able to decouple programming code from the visual aspects, and change functionality without actually touching code.
I think I need to blog about this some day.
from plates.
Martin,
This brings up a couple of good points, in my implementation the attribute data-bind="person" is removed during the template render, consider the syntax data-text="name" when you are binding to for example an a tags anchor text, I kinda like this as it's more explicit and allows for a data-bind and a data-text to live on the same html tag, I believe I had one case where this was necessary.
I do like the cleanliness of syntax like data-href=""... the rule would be something like if it's not data-bind or data-text then the format data-attributeName is assumed. In the case of data-href="" since it's replaced with href="" during the render process you would not have collisions.
Still thinking on this one...
Mike
from plates.
+1 for a way to bind attributes. There needs to be a way to modify attributes such as href.
from plates.
appinsanity: Removing the binding information from the html would be problematic for me as I use it to write data back into models when in the browser. Flow is like this: Load model from server, create html through plates from model, on update of value (keystroke, click) update model.
I do think that anything binding related should start with data-bind, it makes it clear to plates and the casual reader that data binding is taking place. If a developer encounters a tag like data-href= intent would not be immediately clear, with data-bind-href it would be obvious though.
In any case, we need this fast. At least I do :)
from plates.
Martin,
What do you think of this syntax for data-bind:
<a data-bind="href:url, text:title"></a>
<script>
var data = {
title: "gitgub",
url: "https://github.com/"
}
</script>
With this syntax data-bind would be removed during the render process, but you could re-inject additional data-bind or data-tweets-from-user etc...
Mike
from plates.
Hi Mike, not a friend of this, to be honest. this adds a lot of complexity and removes understandability. Knockout.js seems to have a similar problem. I had a bit of a rough day, but I am working on the reverse (binding from dom to models) thursday, which should give some more insights.
from plates.
done. it works like this...
var html = '<span></span><img id="bar" class="foo bazz" src=""/>';
var data = { "bazz": "Hello, World" };
var options = { "bazz": ["class", "src"] };
var output = Plates.bind(html, data, options);
from plates.
Related Issues (20)
- .append() or .partial doesn't work with inputs HOT 1
- Partials HOT 1
- Tests failing on latest Node.js HOT 1
- State of this library HOT 3
- Overrides elements with bad content HOT 2
- Plates (fork?) with some DSL HOT 1
- Collection iteration HOT 1
- Binding doesn't work as expected HOT 1
- Question, not Issue: Getting the innerHTML of a tag for multi-language support
- Not able to get the correct HTML output
- BUG: "Template" may not contain "Subtemplates" tag name HOT 1
- Old Version on Bower HOT 1
- Example project with template nesting HOT 1
- Mapping the same partial multiple times with collections example
- Map to a valueless attribute
- Multiple clauses does not render correctly HOT 2
- Option to allow/disallow undefined attributes HOT 1
- Better common.js support HOT 1
- Provide a proper way to avoid XSS attacks
- Problem with function compileMappings, and how i (might have) fixed it.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plates.