knockout-templating

Replace container element when using Knockout component

你。 提交于 2019-12-01 17:57:05
Is there a way to configure a Knockout component to replace the container element instead of nesting its content inside the container element? For example, if I have a custom component registered as my-custom-element with the following template: <tr> <p>Hello world!</p> </tr> Is it possible to use the component like this: <table> <tbody> <my-custom-element></my-custom-element> </tbody> </table> And have the final product be this: <table> <tbody> <tr> <p>Hello world!</p> </tr> </tbody> </table> Instead of this: (the way Knockout renders components by default) <table> <tbody> <my-custom-element>

KnockoutJS bind event after template render

时光毁灭记忆、已成空白 提交于 2019-11-30 11:14:04
I've been searching for a while, and I'm pretty confident this is a new question, and not a repeat like the title suggests. :) Basically, I'm trying to find out if there is a subscribe-able event that KnockoutJS creates after a template render when using something like jQuery templates. I'd use the built-in "afterRender" but I found out that it doesn't fire if the observable array is cleared. I built this demo to illustrate that problem: http://jsfiddle.net/farina/YWfV8/1/ . Also, I'm aware that I could write a custom handler...but that seems really unnecessary for what I need. I just want one

Using an external Template in KnockoutJS

浪尽此生 提交于 2019-11-30 06:42:53
is it possible to use an external Template in KnockoutJS like this? <script type="text/html" id="a_template" src="templates/a_template.html"> </script> I've tried this solution but didn't get it working. You could also look at: https://github.com/ifandelse/Knockout.js-External-Template-Engine You can use jquery to dynamically load html into a script element, and then execute knockout based on that. <script type="text/html" id="template_holder"></script> <script type="text/javascript"> $('#template_holder').load('templates/a_template.html', function() { alert('Load was performed.'); //knockout

Knockout template using data-bind to image src property not working

寵の児 提交于 2019-11-29 22:00:37
I cannot see what is wrong here but the image does not display using the following Knockout template: <script type="text/html" id="legend-template"> <div><input type="checkbox" data-bind="click : doSomething" ></input> <img width="16px" height="16px" data-bind="src: 'imagePath'" /> <span data-bind="text : label"> </span> </div> </script> The object this is being bound to looks like this: tut.myObject= function (imagePath, label) { this.label = ko.observable(label); this.imagePath = ko.observable(imagePath || liveString + '/Content/images/marker.png'); }; tut.myObject.prototype = { doSomething:

Knockout template using data-bind to image src property not working

老子叫甜甜 提交于 2019-11-28 18:09:26
问题 I cannot see what is wrong here but the image does not display using the following Knockout template: <script type="text/html" id="legend-template"> <div><input type="checkbox" data-bind="click : doSomething" ></input> <img width="16px" height="16px" data-bind="src: 'imagePath'" /> <span data-bind="text : label"> </span> </div> </script> The object this is being bound to looks like this: tut.myObject= function (imagePath, label) { this.label = ko.observable(label); this.imagePath = ko