The plugin for the knockout switch does not hide / show the correct value

I use the plugin with a plugin extension for the knockout version , and it’s hard for me to work with it even with the simplest code. Using knockout 3.0, below is the code I'm using; and I am logical! and another text will be shown to me.

// Javascript ko.applyBindings({type: 'integer'}); <!-- Html bindings --> <div> <!-- ko switch: type --> <!-- ko case: 'boolean' --> <span> Im a boolean!</span> <!-- /ko --> <!-- ko case: $else --> <span> Im an other!</span> <!-- /ko --> <!-- /ko --> </div> 

Here's the JSFiddle of the code. Am I doing something wrong with using this plugin?

-1
source share
2 answers

Your problem is that the ko-switch plugin is not loaded into your script.

The manji solution may not work in some browser (for example, IE11) due to the forced use of the mime type: github does not return the js source file with the mime javascript type, which IE refuses to run with error SEC7112.

Here is a fiddle that works. Instead, I refer to the plugin on rawgithub.com (don't notice that there is no point in raw.github.com):

 <script src="http://rawgithub.com/mbest/knockout-switch-case/master/knockout-switchcase.min.js"></script> <span data-bind='text:type'></span> <div> <!-- ko switch: type --> <!-- ko case: 'boolean' --> Im a boolean! <!-- /ko --> <!-- ko case: $else --> <span> Im an other!</span> <!-- /ko --> <!-- /ko --> </div> 

http://jsfiddle.net/a5H92/1/

Tip. To find the error, I only had to look at the console of my browser.

EDIT : sorry I inserted the wrong code, but the violin was right;)

+1
source

You are linking to a github script page, not a script file.

The right way is: https://raw.githubusercontent.com/mbest/knockout-switch-case/master/knockout-switch-case.min.js .

PS: For JSFiddle, the <script> tag attribute must be equal to text/javascript .

Demo: JSFiddle

+2
source

All Articles