淘汰赛开关案例插件未隐藏/显示正确的值 [英] Knockout switch-case plugin is not hiding/showing the correct value

查看:51
本文介绍了淘汰赛开关案例插件未隐藏/显示正确的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 knockout-switch-case扩展插件,我在即使使用最简单的代码也很难工作.使用淘汰赛3.0,下面是我正在使用的代码;会同时显示我是布尔值!我是另一个文本.

I'm using the knockout-switch-case extension plugin, and I am having a difficult time getting it to work with even the simplest of code. Using knockout 3.0, below is the code I'm using; both the I'm a boolean! and I'm an other text will be shown.

// 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>

这是代码的 JSFiddle .使用此插件时我做错了什么吗?

Here's a JSFiddle of the code. Am I doing something incorrect in use of this plugin?

推荐答案

您的问题是小提琴中未加载ko-switch插件.

Your problem is that the ko-switch plugin is not loaded in your fiddle.

manji解决方案可能由于强制执行mime类型而无法在某些浏览器(例如IE11)中工作:github不会返回具有JavaScript mime类型的原始js文件,而IE拒绝执行此错误,而IE71则执行错误SEC7112.

manji solution may not work in some browser (e.g. IE11) because of mime type enforcement: github doesn't return the raw js file with a javascript mime type, which IE refuses to execute with error SEC7112.

这是一个有效的小提琴.我已经在rawgithub.com上引用了该插件(注意raw.github.com中没有点):

Here's a fiddle that works. I've referenced the plugin at rawgithub.com instead (notice there's no dot like 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 my browser console.

编辑:抱歉,我粘贴了错误的代码,但小提琴是正确的;)

EDIT: sorry I pasted the wrong code, but the fiddle was right ;)

这篇关于淘汰赛开关案例插件未隐藏/显示正确的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆