简体   繁体   English

与 Kendo Observable Binding 一起使用时是否可以更改 Kendo Switch 标签? [剑道-UI]

[英]Is it possible to change Kendo Switch Labels when using it with Kendo Observable Binding? [Kendo-UI]

<input id="switch" data-role="switch" data-bind="enabled: isEnabled, visible: isVisible, checked: isChecked, events: { change: onChange }" />

Switch value: <span id="span"></span>



<script>
  var obs = kendo.observable({
    isChecked: true,
    isEnabled: true,
    isVisible: true,
    onChange: function (e) {
      var value = e.checked ? "ON" : "OFF";
      document.getElementById("span").innerHTML = value;
    }
  });

  kendo.bind($("#switch"), obs);
</script>

Here is how I am binding the value of true or false to display kendo switch.这是我如何绑定 true 或 false 的值来显示剑道开关。

By default the switch labels are "On" or "Off", I want to change them to "Y" or "N" respectively.默认情况下,开关标签是“开”或“关”,我想分别将它们更改为“Y”或“N”。

https://dojo.telerik.com/uDiGifEm I have added a working example here in case anyone wants to refer.我在这里添加了一个工作示例,以防有人想参考。

I have tried to overwrite using css and also tried using the kendo mobile switch to implement a switch but I have a requirement to use observable binding.我曾尝试使用 css 覆盖,还尝试使用剑道移动开关来实现开关,但我需要使用可观察绑定。 I have hardcoded enabled to true here but in real scenario it is bound with a json object boolean value so on change method is used to update if the value is changed.我已在此处硬编码启用为 true,但在实际情况下,它与 json object boolean 值绑定,因此如果值更改,则使用更改方法进行更新。

Add this to your switch declaration:将此添加到您的开关声明中:

data-messages="{ checked: 'Y', unchecked: 'N' }"

API reference: https://docs.telerik.com/kendo-ui/api/javascript/ui/switch/configuration/messages API 参考: https://docs.telerik.com/kendo-ui/api/javascript/ui/switch/configuration/messages

Most of the kendo API documentation examples are in jquery plugin syntax but all work with mvvm declarative syntax as well.大多数剑道 API 文档示例都采用 jquery 插件语法,但也都适用于 mvvm 声明性语法。 Simply prefix the option with "data-" in your html.只需在 html 中为选项添加“data-”前缀即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM