如何通过单个请求获取多个节点?
How to get multiple nodes by single request?
枪 0.8.8
是否可以通过一个get请求获取多个节点?
例如,像这样的东西
gun.mget([ "nodeNameA", "nodeNameB" ], function(value)
console.log(value);
/*
{
"nodeNameA": { my: "Special", variable: 123 },
"nodeNameB": { the: "Glory", answer: 42 }
}
*/
// ... do something ...
});
在许多数据库中,您可以通过一次查询获取多个对象。由于网络延迟,有时获得单个响应比获得数百个小响应更快。
@trex ,
在 table 上使用扩展的 API .open(cb)
可能就是您想要的。
这是一个例子:
var gun = Gun();
gun.get('nodeNameA').put({ my: "Special", variable: 123 });
gun.get('table').set(gun.get('nodeNameA'));
gun.get('nodeNameB').put({ the: "Glory", answer: 42 });
gun.get('table').set(gun.get('nodeNameB'));
gun.get('table').open(function(data, key){
console.log("update:", data);
/*
{
"nodeNameA": { my: "Special", variable: 123 },
"nodeNameB": { the: "Glory", answer: 42 }
}
*/
});
在这里自己玩:http://jsbin.com/ditohivovo/edit?js,console !
文档 可在此处获得:
https://github.com/amark/gun/wiki/API#open
Note: You must include it with require('lib/open.js')
or <script src="gun/lib/open.js"></script>
in the browser.
枪 0.8.8
是否可以通过一个get请求获取多个节点?
例如,像这样的东西
gun.mget([ "nodeNameA", "nodeNameB" ], function(value)
console.log(value);
/*
{
"nodeNameA": { my: "Special", variable: 123 },
"nodeNameB": { the: "Glory", answer: 42 }
}
*/
// ... do something ...
});
在许多数据库中,您可以通过一次查询获取多个对象。由于网络延迟,有时获得单个响应比获得数百个小响应更快。
@trex ,
在 table 上使用扩展的 API .open(cb)
可能就是您想要的。
这是一个例子:
var gun = Gun();
gun.get('nodeNameA').put({ my: "Special", variable: 123 });
gun.get('table').set(gun.get('nodeNameA'));
gun.get('nodeNameB').put({ the: "Glory", answer: 42 });
gun.get('table').set(gun.get('nodeNameB'));
gun.get('table').open(function(data, key){
console.log("update:", data);
/*
{
"nodeNameA": { my: "Special", variable: 123 },
"nodeNameB": { the: "Glory", answer: 42 }
}
*/
});
在这里自己玩:http://jsbin.com/ditohivovo/edit?js,console !
文档 可在此处获得:
https://github.com/amark/gun/wiki/API#open
Note: You must include it with
require('lib/open.js')
or<script src="gun/lib/open.js"></script>
in the browser.