jquery-templates

jQuery Template - Executing JS code inside the template

て烟熏妆下的殇ゞ 提交于 2019-12-05 11:01:01
I am trying to learn more about jQuery templates but cant seem to execute any JS calls inside the template. <script id="log-item" type="text/x-jquery-tmpl"> {{if title.length }} <h3 style="padding-bottom:5px;">${ title }</h3> {{/if}} objectToString(${ detail }); </script> Note that my objectToString() function is never called, just rendered out as a string. I tried wrapping it in {{ }} on a whim but no luck. Anyone out there who can help? Anthony, you can. The method your calling needs to be inside a template tag like so: <script id="log-item" type="text/x-jquery-tmpl"> {{if title.length }}

Building HTML with templates versus building it in javascript?

别来无恙 提交于 2019-12-05 08:32:22
I recently started making web apps, and while I make some stuff that works, I'm not sure of the best practices. Up to now, I've mostly used the templating systems of Django, web.py and PHP. But now that I'm using jQuery and nice ajaxy magic to get data from the server without refreshing the client, I'm seeing the advantages of building the HTML directly in javascript (so I can just send a small json object to the client and have him figure out what to change and how). So now I have some bits that are rendered with templates, and some that are built in javascript, and even one horrid case where

How to render HTML as rendered HTML in jQuery.tmpl()?

孤者浪人 提交于 2019-12-05 06:31:04
I can't assign HTML properly using jQuery.tmpl(). If i pass value of something as html tag it is rendered as as it is instead of HTML tags rendered on page <div id="window"> <script id="lines" type="text/x-jquery-tmpl"> <div id="${id}" class="line ${type}"><span>${name}</span>: ${body}</div> </script> </div> var line = { name: 'John', body: '<strong>hello</strong> }; $('#lines').tmpl(line).appendTo('#window'); You can wrap the template variable with {{html body}} to override the default encoding behavior. 来源: https://stackoverflow.com/questions/6248962/how-to-render-html-as-rendered-html-in

Why should we wrap our templates inside script blocks?

只愿长相守 提交于 2019-12-05 05:01:21
Background All the JS template engines recommend putting your template text inside script blocks like so: <script id="peopleTemplate" type="text/template"> {#people} <div class="person">Name: {firstName} {lastName}</div> {/people} </script> but many developers (understandably) dislike this because they lose HTML syntax highlighting in their code editor inside the script block. I've seen the workarounds like this: Keep correct HTML syntax highlighting in <script> "text/html" templates . This question is not asking about workarounds. I know one danger is that web browsers will attempt to fix

Using external composite jQuery Templates

我是研究僧i 提交于 2019-12-05 02:11:21
问题 I wanted to try out jQuery Templates after being inspired by these 2 blog postings http://encosia.com/2010/11/10/composition-with-jquery-templates-why-and-how/ http://encosia.com/2010/10/05/using-external-templates-with-jquery-templates/ Well, it's not quite working for me. If I have the template code on the page itself it works fine, but loading remotely isn't working for me. It appears the template is being retrieved ok. what is wrong here? External template: <script id="contactsTemplate"

Can jQuery template bind to a raw array

旧街凉风 提交于 2019-12-04 20:58:28
问题 Given <div id="place_holder" /> <script id="template" type="text/x-jquery-tmpl"> WHAT DO I PUT HERE </script> var array_of_ints = [1,2,3] $( "#template" ) .tmpl( array_of_ints ) .appendTo( "#place_holder" ); What can I put within the template to get ? <ul> <li>1</li> <li>2</li> <li>3</li> </ul> 回答1: <ul id="place_holder"> </ul> <script id="template" type="text/x-jquery-tmpl"> <li>${}</li> </script> var array_of_ints = [1,2,3] $("#template") .tmpl(array_of_ints) .appendTo( "#place_holder" );

Use MVC helpers inside jquery.tmpl templates

北战南征 提交于 2019-12-04 19:53:44
I have a simple foreach template and inside every element I want an ActionLink but that ActionLink needs to send an Id to edit the element. The item to be templated: <div data-bind="template: { name: 'postsTemplate', foreach: posts }"> </div> The template: <script id="postsTemplate" type="text/html"> <h2 data-bind="text: Title"></h2> <p class="post-info"> <p class="post-info" data-bind="text UserName"></p> <span data-bind="Body"></span> <p class="post-footer"> @Html.ActionLink("Comments", "IndividualPost", "Post", null, null, "comments", new {id = }) </p> </p> </script> How can I send the

Getting “$item is not defined” on applyBindings

纵饮孤独 提交于 2019-12-04 19:41:04
I'm trying to use knockout to do a pretty basic binding but am having trouble accessing the $item variable from jquery.tmpl. I keep getting " $item is not defined" when I apply the bindings. I've done this before so I know it can be done but I can't figure out why it is not working in this case. What's interesting is if I remove templateOptions:{parentItem: $item} , then everything works as expected. I've included the following files <script type="text/javascript" src="Extension/resources/jquery.1.6.1.js"></script> <script type="text/javascript" src="Extension/resources/jquery.tmpl.js"><

Making JQuery templates reusable

别等时光非礼了梦想. 提交于 2019-12-04 17:56:36
I want to create a jQuery template(s) that will be used project wide. I would prefer to put the templates in a separate file or files and compile them on project start up using the template function. I don't want to have the templates in the markup, in script tags. Is this possible and how would I do it? As RoccoC5 suggested it, you can define a small plugin which will fetch your remote template and then append its content into a script tag to the head: (function ($) { $.loadTmpl = function (url, name) { return $.get(url).success(function (content){ $("head").append($('<script/>', { id: name,

jQuery templates plugin: how to create two-way binding?

徘徊边缘 提交于 2019-12-04 16:56:34
I started using jQuery templates plugin (the one Microsoft created), but now I face this problem: the template is for a bunch of forms bound to an array of objects; when I change something on one of the forms, I want the bound object to update and I can't figure out how to automate that. Here's a simple example (real life template and object are much more complex) : <!-- Template --> <script type="text/html" id="tmplTest"> <input type="text" value="${textvalue}"/> </script> <!-- object to bind --> <script type="text/javascript"> var obj = [{textvalue : "text1"},{textvalue : "text2"}] jQuery("