{"action":"created","issue":{"url":"https://api.github.com/repos/weexteam/article/issues/78","repository_url":"https://api.github.com/repos/weexteam/article","labels_url":"https://api.github.com/repos/weexteam/article/issues/78/labels{/name}","comments_url":"https://api.github.com/repos/weexteam/article/issues/78/comments","events_url":"https://api.github.com/repos/weexteam/article/issues/78/events","html_url":"https://github.com/weexteam/article/issues/78","id":176164536,"number":78,"title":"Storage","user":{"login":"jiuyuegui","id":7759642,"avatar_url":"https://avatars.githubusercontent.com/u/7759642?v=3","gravatar_id":"","url":"https://api.github.com/users/jiuyuegui","html_url":"https://github.com/jiuyuegui","followers_url":"https://api.github.com/users/jiuyuegui/followers","following_url":"https://api.github.com/users/jiuyuegui/following{/other_user}","gists_url":"https://api.github.com/users/jiuyuegui/gists{/gist_id}","starred_url":"https://api.github.com/users/jiuyuegui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jiuyuegui/subscriptions","organizations_url":"https://api.github.com/users/jiuyuegui/orgs","repos_url":"https://api.github.com/users/jiuyuegui/repos","events_url":"https://api.github.com/users/jiuyuegui/events{/privacy}","received_events_url":"https://api.github.com/users/jiuyuegui/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-09-10T07:14:36Z","updated_at":"2016-12-09T09:30:43Z","closed_at":null,"body":"> [英文原文](http://alibaba.github.io/weex/doc/modules/storage.html)\n# 提要\n\nweex版本 >= 0.7\n\n`storage`有一系列的接口，有很多操作，例如添加/修改/删除本地存储数据\n# API\n## setItem(key, value, callback)\n\n该方法可以通过键值对的形式将数据存储到本地。同时可以通过该方法，更新已有的数据。\n### 参数\n- key(string): 要存储的值的名称，不允许是\"\"或null.\n- value(string): 要换存的值，不允许是\"\"或null.\n- callback(object): 执行操作成功后的回调.\n### 示例\n\n``` javascript\n    var storage = require('@weex-module/storage');\n    storage.setItem('bar', 'bar-value', function(e) {\n      // 'e'是一个包含'result'和'data'的对象. e.result判断'setItem'操作是否执行成功.\n      // e.data返回'undefined'表示设置成功，返回'invalid_param'表示key/value为\"\"/null\n    });\n```\n## getItem(key, callback)\n\n传入键名返回对应的键值\n### 参数\n- key(string): 要获取的值的名称，不允许是\"\"或null.\n- callback(object): 执行操作成功后的回调.\n### 示例\n\n``` javascript\n    var storage = require('@weex-module/storage');\n    storage.getItem('foo', function(e) {\n      // 'e'是一个包含'result'和'data'的对象.\n      // 使用'e.data'获取键的值，如果没有找到对应的键值则返回'undefined'.\n    });\n```\n## removeItem(key, callback)\n\n传入一个键名将会删除本地存储中对应的键值\n### 参数\n- key(string): 要删除的值的名称，不允许是\"\"或null.\n- callback(object): 执行操作成功后的回调.\n### 示例\n\n``` javascript\n    var storage = require('@weex-module/storage');\n    storage.removeItem('foo', function(e) {\n      // 'e'是一个包含'result'和'data'的对象.\n      // e.result返回执行结果'success'或'failed'.\n      // e.data在成功执行后返回'undefined'.\n    });\n```\n## length(callback)\n\n返回本地存储的数据中所有存储项数量的整数\n### 参数\n- callback(object): 执行操作成功后的回调.\n### 示例\n\n``` javascript\n    var storage = require('@weex-module/storage');\n    storage.length(function(e) {\n      // 'e'是一个包含'result'和'data'的对象.\n      // e.data返回所有已存储项的数量.\n    });\n```\n## getAllKeys(callback)\n\n返回一个包含全部已存储项键名的数组\n### 参数\n- callback(object): 执行操作成功后的回调.\n### 示例\n\n``` javascript\n    var storage = require('@weex-module/storage');\n    storage.getAllKeys(function(e) {\n      // 'e'是一个包含'result'和'data'的对象.\n      // e.data返回键名组成的数组.\n    });\n```\n"},"comment":{"url":"https://api.github.com/repos/weexteam/article/issues/comments/265970885","html_url":"https://github.com/weexteam/article/issues/78#issuecomment-265970885","issue_url":"https://api.github.com/repos/weexteam/article/issues/78","id":265970885,"user":{"login":"Jinjiang","id":206848,"avatar_url":"https://avatars.githubusercontent.com/u/206848?v=3","gravatar_id":"","url":"https://api.github.com/users/Jinjiang","html_url":"https://github.com/Jinjiang","followers_url":"https://api.github.com/users/Jinjiang/followers","following_url":"https://api.github.com/users/Jinjiang/following{/other_user}","gists_url":"https://api.github.com/users/Jinjiang/gists{/gist_id}","starred_url":"https://api.github.com/users/Jinjiang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jinjiang/subscriptions","organizations_url":"https://api.github.com/users/Jinjiang/orgs","repos_url":"https://api.github.com/users/Jinjiang/repos","events_url":"https://api.github.com/users/Jinjiang/events{/privacy}","received_events_url":"https://api.github.com/users/Jinjiang/received_events","type":"User","site_admin":false},"created_at":"2016-12-09T09:30:42Z","updated_at":"2016-12-09T09:30:42Z","body":"@aizhimin 还有一种思路是参考 [web sql database](https://www.w3.org/TR/webdatabase/)，其实就是包装了一层 sql 语句，底层是 sqlite，不过这个规范已经被 w3c 废弃了，webkit 对这个规范做了实现，可以作为参考"}}
{"actor":{"display_login":"Jinjiang"}}