Kendo模板中的Switch语句 [英] Switch Statement in Kendo Template

查看:364
本文介绍了Kendo模板中的Switch语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Kendo模板,并且能够按照文档中的说明创建条件语句(IF语句). 这是我的代码.

Im using Kendo Template and I was able to create a conditional statement (IF statement) as stated on the documentaion. Here's my code.

#if ((item.ControlType) == "tbx"){#
   @(Html.Kendo().AutoComplete()
   .Name("#=ctrlid#")
   .ToClientTemplate())
#}#

这很好.

但是我想要的是 Switch Case 声明.我已经尝试过了,但是没有用.它显示无效模板".

But what I'd like to have is a Switch Case Statement. I've tried this but it doesn't work. It says "Invalid Template".

# switch (item.ControlType) {#
  # case "tbx": #
     @(Html.Kendo().AutoComplete()
       .Name("#=ctrlid#")
       .ToClientTemplate())
  # break; #
  # }#

我错过了什么吗?还是Kendo模板无法解释Switch Case语句? (关于后者,我不这样认为.我肯定缺少某些东西)

Am I missing something? Or is it just impossible for Kendo Template to interpret Switch Case Statements? (about the latter, I dont think so..I'm definitely missing something)

有人可以帮我吗?谢谢!^^

Can anyone help me please? Thanks!^^

推荐答案

我检查了您的情况,发现了错误的原因.基本上,要使JavaScript保持有效,您只需要在switch语句和第一个case语句之间使用一对#符号即可.

I check your case and I found the reason for the error. Basically to keep the JavaScript valid you will have to use only one pair of # symbols surounding the switch statement and the first case statement.

例如

代替:

# switch (item.ControlType) {#
# case "tbx": #

使用:

# switch (item.ControlType) {
  case "tbx": #

为了演示它,这是一个 jsbin .如果将开关与MVC包装器生成的某些小部件组合在一起,则基本上不会有问题.如果有,让我知道.

To demonstrate it , here is a jsbin. Basically there should not be problems if you combine the switch with some widget generated by the MVC wrappers. If there is, let me know.

这篇关于Kendo模板中的Switch语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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