jquery-templates

How to use HTML5 drag and drop in combination with KnockoutJS?

耗尽温柔 提交于 2019-12-04 15:40:33
问题 I can't seem to bind to html5 drag and drop events. Here's an example of from a template: <script id="tabsTemplate" type="text/html"> <div class="dropzone" for="tab" data-bind="event:{dragover: function(event){event.preventDefault();}, dragenter: function(event){event.target.addClass('dragover'); event.preventDefault();}, dragleave: function(event){event.target.removeClass('dragover'); event.preventDefault();}} drop: function(event){console.log('blahblah!')}"></div> <h1 class="tab" draggable=

Can I do a jquery-tmpl each over object properties

可紊 提交于 2019-12-04 09:21:30
问题 The template {{each}} directive works great for iterating over an array like this: var myArray = ["a","b","c"]; I'm wondering if there is an equivalent for iterating over object properties, i.e.: var myObj = {"propOne": "a", "propTwo": "b", "propThree": "c"}; I'd like a template that would let me output as <ul> <li><span>propOne</span><span>a</span></li> .... etc For bonus points I'd like to use this template from KnockoutJS. 回答1: Actually {{each}} will walk through properties on an object.

Knockout and jQuery autocomplete

蓝咒 提交于 2019-12-04 02:12:27
Knockout value binding doesn't work with jquery autocomplte. How to get it working? I have a template: <input type="text" class="autocomplete" data-bind="value: viewModelObservableValue" name="MyValue" /> After template rendering I am applying jQuery autocomplete on an input. Binding doesn't work. See my jsfiddle . It works only if ko.applyBindings(viewModel) goes after $(..).autocomplete(..); Rene Pot It looks like jQuery autocomplete hijacked the change event. Thats why it doesn't work. To fix this, you'll have to set the valueUpdate property to blur . Of course, this won't trigger after

Improve jQuery template performance

风流意气都作罢 提交于 2019-12-04 00:28:50
Update Apparently, jQuery templates can be compiled and it helps performance for templates with if statements shown here . But as shown here , the precompiled jQuery templates doesn't do much for my case since my template contains no logic block. For those who are suggesting the use of another templating engine, ideally I would like to use just jQuery templates as everyone on the team knows just jQuery. There is also this test case that compares a few templating engine. Hi, Just today I was told that there are performance issues with using jQuery templates. To compare, I have used jQuery

Using external composite jQuery Templates

二次信任 提交于 2019-12-03 16:26:14
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" type="text/x-jquery-tmpl"> <table class="contacts"> <thead><tr><td class="ui-helper-hidden">Id</td><td

defining new variable within jquery template

强颜欢笑 提交于 2019-12-03 15:37:13
问题 Is it possible to define a new variable within a jquery template? I read the official jquery template docs but could not find anything on this. I tried something like {{ var xxx=123 }} but it didn't work. Finally I am using a hack by doing ${$item.xxx=123,""} and later using $item.xxx but I am sure it is not the best approach... 回答1: I don't think that doing the $item approach is too bad. It is consistent with where you would look for variables that are passed in via the options parameter to

Can jQuery template bind to a raw array

怎甘沉沦 提交于 2019-12-03 13:44:20
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> <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" ); <div id="place_holder" /> <script id="template" type="text/x-jquery-tmpl"> {{= $data}} </script> var array_of

How to use HTML5 drag and drop in combination with KnockoutJS?

那年仲夏 提交于 2019-12-03 09:45:46
I can't seem to bind to html5 drag and drop events. Here's an example of from a template: <script id="tabsTemplate" type="text/html"> <div class="dropzone" for="tab" data-bind="event:{dragover: function(event){event.preventDefault();}, dragenter: function(event){event.target.addClass('dragover'); event.preventDefault();}, dragleave: function(event){event.target.removeClass('dragover'); event.preventDefault();}} drop: function(event){console.log('blahblah!')}"></div> <h1 class="tab" draggable="true" data-bind="attr: {selected: $data.name === $item.selected()}, click: function(){$item.selected(

how to tell if a property exists and is false

岁酱吖の 提交于 2019-12-03 07:29:16
I am having a hard time determining if data passed into the jquery template exists and is false without getting errors. This is what I am using to test <html> <head> <title>jQuery Templates {{if}} logic</title> </head> <body> <p id="results"></p> <p>How do you test if the Value exists and is false?</p> <script id="testTemplate" type="text/html"> Test ${Test}: {{if Value}} Value exists and is true {{else}} Value doesn't exist or is false {{/if}} <br/> </script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text

defining new variable within jquery template

六月ゝ 毕业季﹏ 提交于 2019-12-03 06:01:03
Is it possible to define a new variable within a jquery template? I read the official jquery template docs but could not find anything on this. I tried something like {{ var xxx=123 }} but it didn't work. Finally I am using a hack by doing ${$item.xxx=123,""} and later using $item.xxx but I am sure it is not the best approach... I don't think that doing the $item approach is too bad. It is consistent with where you would look for variables that are passed in via the options parameter to $.tmpl. Another approach that I have used, based on a small tip here , is to actually define a "var"