visible绑定(The "visible" binding)
对visible进行绑定可以控制元素的显示和隐藏。
示例:
<div data-bind="visible: shouldShowMessage">
You will see this message only when "shouldShowMessage" holds a true value.
</div>
<script type="text/javascript">
var viewModel = {
shouldShowMessage: ko.observable(true) // Message initially visible
};
viewModel.shouldShowMessage(false); // ... now it's hidden
viewModel.shouldShowMessage(true); // ... now it's visible again
</script>
参数说明:
- Main parameter
- 当参数值是False时(包括数字0,或者null, undefined),绑定的元素会被设置style.display为none,元素隐藏。这会覆盖你写的其他样式。
- 当参数是true时(包括true, 非空对象或数组),绑定的元素style.display会被移除,元素可见。
如果绑定到visible的属性是observable的,则当值改变时,元素的可见或者隐藏也会动态的更改。如果绑定上的值不是observable的,那么只在第一次绑定时会生效,后面更改这个值是不会影响到元素的可见与否的。
- Add parameters
- 无
注:使用函数和表达式控制元素的可见
也可以使用JS函数或者表达式来赋值,KO会根据函数或者表达式的值来动态的控制元素的显示和隐藏。
示例:
<div data-bind="visible: myValues().length > 0">
You will see this message only when 'myValues' has at least one member.
</div> <script type="text/javascript">
var viewModel = {
myValues: ko.observableArray([]) // Initially empty, so message hidden
};
viewModel.myValues.push("some value"); // Now visible
</script>
依赖
无,除了Knockout的核心库外。
visible绑定(The "visible" binding)的更多相关文章
- Knockout v3.4.0 中文版教程-10-绑定-控制文本内容和外观-visible绑定
4.绑定 1. 控制文本内容和外观 1. visible绑定 目的 visible绑定可以根据你传入绑定的值控制关联的DOM元素显示或隐藏. 例子 <div data-bind="vi ...
- Knockout与Require框架同时使用时的visible绑定的问题,造成的影响,以及解决的方法。
Knockout 可以将 visible 绑定到DOM 元素上,使得该元素的hidden 或visible 状态取决于绑定的值. 查看以下knockout的描述,http://knockoutjs.c ...
- Knockout 新版应用开发教程之"visible"绑定
"visible" 绑定 用途 DOM元素的显示或者隐藏是根据绑定的值来的,前提是将visible绑定给该元素 例子 <div data-bind="visible ...
- Visible 绑定
目的 Visible绑定通过绑定一个值来确定DOM元素显示或隐藏 <script src="knockout.js"></script><div da ...
- Knockout.Js官网学习(visible绑定)
前言 让visible绑定到DOM元素上,使得该元素的hidden或visible取决于绑定的值. 简单的绑定 首先还是先定义一个ViewModel var AppViewModel = { shou ...
- 背水一战 Windows 10 (22) - 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合
[源码下载] 背水一战 Windows 10 (22) - 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合 作 ...
- 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合
背水一战 Windows 10 之 绑定 通过 Binding 绑定对象 通过 x:Bind 绑定对象 通过 Binding 绑定集合 通过 x:Bind 绑定集合 示例1.演示如何通过 Bindin ...
- Knockout.js Visible绑定
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...
- WPF:在XmlDataProvider上使用主-从绑定(Master-Detail Binding)
原文 http://www.cnblogs.com/mgen/archive/2011/06/19/2084553.html 示例程序: 如上程序截图,一目了然典型的主从模式绑定应用,如果里面的数据不 ...
随机推荐
- C# 导出Word
导出word文档(无模版): using Microsoft.Office.Interop.Word; public static string CreateWordFile(CaseVM model ...
- 利用Paramiko模块远程连接Linux
使用Paramiko模块模拟SSH远程连接到服务器,并执行命令.(支持Tab键补全) 1.安装相关模块: 1)安装 Crypto 模块: 下载源码包解压 安装: sudo python setup.p ...
- Ubuntu14.04浏览器Firefox安装flash播放插件
sudo apt-get update sudo apt-get install flashplugin-nonfree ================= 类飞秋软件 sudo apt-get in ...
- Chapter 19_0 位操作库
位操作库是Lua5.2版本里添加的库,所有函数放在bit32 table里.(bit32只能针对32位整数运算) 在Lua5.3版本里,bit32库被废弃掉.不过可以使用一个外部兼容库,但是最好直接用 ...
- 关于去除input type='file'改变组件的默认样式换成自己需要的样式的解决方案
在工作中时常会遇到如需要上传功能的按钮,而不像需要系统默认的样式时候,可以采取以下的解决方案: <img onclick="getElementById('file').click() ...
- NYOJ-1057 寻找最大数(三)(贪心)
寻找最大数(三) 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 给出一个整数N,每次可以移动2个相邻数位上的数字,最多移动K次,得到一个新的整数. 求这个新的整数的 ...
- LeetCode #3. Longest Substring Without Repeating Characters C#
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- 定时帧:NSTimer和CADisplayLink
学习参考了:http://www.jianshu.com/p/c35a81c3b9ebhttps://zsisme.gitbooks.io/ios-/content/chapter11/frame-t ...
- timeit模块 与 time模块,计时的区别
time 模块,理解容易 import time time_start = time.time() time_end = time.time() time_use = time_end - time ...
- 在线预览pdf、xlsx、docx、ppt等文档
使用微软提供的Office Online平台只需要一个网址即可在线查看Xls,doc,PPT等文档 http://view.officeapps.live.com/op/view.aspx?src=要 ...