8. 工具 -- Highway MVVM
来源:互联网 发布:csgom4a1皮肤知乎 编辑:程序博客网 时间:2024/06/03 22:54
Highway内置工具函数,可通过Highway.utils引用
8-1. unique
获取唯一标识
<!-- examples/tools/unique.html -->const id0 = Highway.utils.unique();const id1 = Highway.utils.unique('c');alert(`${id0}, ${id1}`);
8-2. assign
拓展对象
<!-- examples/tools/assign.html -->const obj0 = { a: 'a', b: 'b'};const obj1 = { a: 'aa', c: 'c'};const obj2 = Highway.utils.assign({}, obj0, obj1);alert(JSON.stringify(obj2));
8-3. include
返回数组中指定数据下标,如未找到,返回 -1
<!-- examples/tools/include.html -->const arr = [1, 2, 3, 4];const idx0 = Highway.utils.include(arr, 5);const idx1 = Highway.utils.include(arr, 2);alert(`${idx0},${idx1}`);
8-4. isPlainObject
是否为原生Object对象
<!-- examples/tools/isPlainObject.html -->alert(Highway.utils.isPlainObject({a: 'a'})); // truealert(Highway.utils.isPlainObject([0, 1])); // false
8-5. isDate
是否为日期
<!-- examples/tools/isDate.html -->alert(Highway.utils.isDate({})); // falsealert(Highway.utils.isDate(new Date)); // true
8-6. isObject
是否为对象
<!-- examples/tools/isObject.html -->alert(Highway.utils.isObject({})); // truealert(Highway.utils.isObject(new Date)); // truealert(Highway.utils.isObject(function () {})); // truealert(Highway.utils.isObject(1)); // false
8-7. isNumeric
是否为数字
<!-- examples/tools/isNumeric.html -->alert(Highway.utils.isNumeric(1)); // truealert(Highway.utils.isDate({})); // false
8-8. isTrue
是否为boolean true
<!-- examples/tools/isTrue.html -->alert(Highway.utils.isTrue(true)); // truealert(Highway.utils.isTrue('false')); // falsealert(Highway.utils.isTrue('1')); // true
false、’false’、”、’0’、null、undefined、0均被判断为boolean false,其他均被判断为true
8-9. MapList
映射列表
- add(key, value)
- find(key, value)
- remove(key, value)
- clear()
- keys()
- values()
<!-- examples/tools/MapList.html -->const mapList = new Highway.utils.MapList;mapList.add('a', '0');mapList.add('a', '1');mapList.add('a', '2');console.dir(mapList.find('a')); // ['0', '1', '2']mapList.remove('a', '1');console.dir(mapList.find('a')); // ['0', '2']mapList.add('b', '2');console.dir(mapList.keys()); // ['a', 'b']console.dir(mapList.values()); // ['0', '2', '2']mapList.clear();
8-10. secureHtml
安全HTML编码
““
console.log(Highway.utils.secureHtml(‘
8-10. secureUri
安全URI编码
<!-- examples/tools/secureUri.html -->// http://uri?q=11&<script>alert(1)console.log(Highway.utils.secureHtml('http://uri?q=11&<script>alert(1)'));
8-11. getAttrs
获取DOM元素所有属性
<div id="attr" directive-0:attr="exp" style="backgrond-color:red;"></div>//{"id":"attr","directive-0:attr":"exp","style":"backgrond-color:red;"}console.dir(Highway.utils.getAttrs($('#attr')));
0 0
- 8. 工具 -- Highway MVVM
- 0. 前言 -- Highway MVVM
- 2. 视图 -- Highway MVVM
- 3. 指令 -- Highway MVVM
- 5. 管道 -- Highway MVVM
- 6. 组件 -- Highway MVVM
- 7. 服务 -- Highway MVVM
- 1. 快速开始 -- Highway MVVM
- 4. 宏指令 -- Highway MVVM
- Highway
- 数据库同步维护工具 for WPF MvvM
- pku1648Countryside Highway
- poj2485 Highway
- hihoCoder1090 Highway
- Highway Networks
- Highway Network
- poj1751 highway
- Highway Networks
- 浅谈正则化
- 7. 服务 -- Highway MVVM
- Spring XML小结
- tensorflow 使用nearest最邻近算法 分类mnist数据库
- 一款社交教育类问答游戏的在线匹配问题
- 8. 工具 -- Highway MVVM
- 扩展已知类的功能
- Canvas
- 进程操作
- CentOS修改mysql 用户root的密码并允许远程登录
- 深入解读Spring Framework事务管理(第五弹:同时执行事务通知和自定义的分析通知)
- 简易动态进度条实现
- iOS开发怎么获取本地数据和把数据存储到本地
- 开始用FairyGUI和KBEngine重写uMMORPG