Comments (8)
You should initialize your data with any necessary defaults, instead of putting that into the template.
from jquery-tmpl.
Sometimes you don't want to modify the data. For example other 'clients' may be accessing the data. It may be being round-tripped to the server. Keeping this open as a feature request to be considered. (It's is something others have asked for too, and which I have been considering.)
from jquery-tmpl.
That would invite a ton of otherwise unnecessary features. If you can't modify the original data, you can always make a deep copy with $.extend(true, {}, originalData)
from jquery-tmpl.
Agree you can do that. We have to find the right balance... Default values may be a strong enough scenario not to want to force cloning of data every time you need a view to fall back to a default string in the case of jagged data, for example. Not saying we have to do it though. Just tracking it for now... :-)
from jquery-tmpl.
The use case I have is a template that is very commonly used, and the default behaviour produces a html block that contains a lot of default css classes (~20). User contributed javascript utilises the templates in a widget kind of pattern. I need to make it optional for the user to override the css styles on the widget, but as a percentage of actual uses, this is not common. Being forced to do it in the data means my users need to supply the ~20 default css classes in the template data, when in general they really just want to supply the data object received from the server. The additional js code overhead is significant, especially when I don't want to burden them with even being aware of the css classes until they discover a need to override them.
Sure I could wrap/proxy my various template calls in additional js methods that modify the data, but again, it is a lot messier than needed. It also means I introduce a non-standard API for template use - it is much easier to say to someone 'learn jqeuery templates' than 'learn my custom API that I needed to write to handle defaults'. This is a fairly specific use case (default values) and I can see a lot of situations beyond mine where this feature would significantly reduce the complexity of the client code. Cheers,
Colin
from jquery-tmpl.
I too see a need for default values.
- I want my view/template to decide what it wants to output as default values, not my logic behind the view.
- Most templating engines (not just js) supports default values. I know that "the others are doing it" is not much of an argument, but sometimes other people have good ideas :)
from jquery-tmpl.
I am looking at including support for default values in the ongoing work at JsRender and JsViews. (See #96 for context re: roadmap).
from jquery-tmpl.
Thanks for taking the time to submit this issue. Just wanted to let you know this plugin is no longer being actively developed or maintained by the jQuery team. See README for more info.
from jquery-tmpl.
Related Issues (20)
- tmpl inside of each HOT 2
- support jQuery 1.7+ ? HOT 1
- README is out of date HOT 5
- Add API Documentation to README HOT 5
- {{switch}} statement is needed for jquery-tmpl HOT 1
- JsView append data with the event attach to it. HOT 2
- http://api.jquery.com/category/plugins/templates/ 这个地址打开就说"Not Found",地址失效啦? HOT 1
- can use jquery-tmpl in Dust ?
- [enhancement] Add missing bower.json.
- You don't seem to be active here. HOT 1
- varaible naming with @ HOT 1
- Can I use jquery template without html file and compile them by some tools like node js HOT 1
- How to process data with PHP in the template HOT 1
- getting mails for every person update stop to receiving mails HOT 1
- How can I get substring from parsed html in jquery.tmpl HOT 2
- Nested tmpls HOT 2
- $obj.tmpl().html() can not return whole html , i need a method to return this dom's whoe html ? HOT 3
- Index of first array element HOT 1
- Unnecessary http request happening when applying template inside ajax success request
- RangeError: Maximum call stack size exceeded
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 jquery-tmpl.