Giter VIP home page Giter VIP logo

Comments (8)

jzaefferer avatar jzaefferer commented on May 17, 2024

You should initialize your data with any necessary defaults, instead of putting that into the template.

from jquery-tmpl.

BorisMoore avatar BorisMoore commented on May 17, 2024

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.

jzaefferer avatar jzaefferer commented on May 17, 2024

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.

BorisMoore avatar BorisMoore commented on May 17, 2024

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.

hawkett avatar hawkett commented on May 17, 2024

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.

pingvinen avatar pingvinen commented on May 17, 2024

I too see a need for default values.

  1. I want my view/template to decide what it wants to output as default values, not my logic behind the view.
  2. 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.

BorisMoore avatar BorisMoore commented on May 17, 2024

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.

rdworth avatar rdworth commented on May 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.