var stallone = {stallone:{first:'Sylvester',last:'Stallone',gender:'male'}};
var gibson = {gibson:{first:'Mel',last:'Gibson',gender:'male'}};
var movies = gun.get('movies')
movies.put(stallone).key('movies/action').key('movies/actors').key('movies/action/rambo') movies.put(gibson).key('movies/action').key('movies/actors').key('movies/action/roadwarrior').key('movies/comedy');
movies.get('movies/action').val();
returns {_: Object, stallone: Object, gibson: Object} Nice.
movies.get('movies/comedy').val();
returns {_: Object, stallone: Object, gibson: Object} Erm..What is Sly doing here? Not Nice!!
gun.get('movies/comedy').val();
returns {_: Object, stallone: Object, gibson: Object} same thing!!
这种行为导致了几个问题:
1)为什么要制作电影?我正在合作,var movies = gun.get('movies')
为什么我必须再次创建带有“电影”的密钥?'movies' 应该自动添加前缀。
2)即使多个键可以工作,它也不是很直观。如果我们能做到就好了
movies.put(gibson).keys(['actors','comedy','action'])
。
注意:如果可以循环完成,我会很高兴。但这不起作用
var gibsonKeys = ['actors','action','comedy','dieHard']
gibsonKeys.forEach(function(key){
movies.put(gibson).key('movies/'+key);
// could be gun.put(gibson).key('movies/'+ key) as well
});
作为旁注......我知道键只是字符串,而不是数据的真实路径;)