视图上下文
概述
存取数据
var view = View.ofId("myView");
/* 获取数据存取上下文 */
var ctx1 = view.getContext();
var ctx2 = view.context;
/* 两种方式等价 */
console.log(ctx1 === ctx2); // -> true
/**
* 存放数据。支持链式调用
*/
ctx1.set("string", "str").set("array", ["str", false]);
/**
* 获取数据量
*/
console.log(ctx1.size()); // -> 2
/**
* 列举key
*/
console.log(ctx1.listKeys()); // -> ["string", "array"]
/**
* 判断是否含有数据
*/
console.log(ctx1.has("string")); // -> true
console.log(ctx1.has("object")); // -> false
/**
* 获取数据
*/
console.log(ctx1.get("string")); // -> "str"
console.log(ctx1.get("object")); // -> undefined
/**
* 删除数据
*/
console.log(ctx1.remove("string")); // -> "str"
console.log(ctx1.remove("string")); // -> undefined
/**
* 清空数据
*/
ctx1.clear();
console.log(ctx1.get("array")); // -> undefined使用建议
Last updated