如何使用javascript函数

时间:2017-10-16 12:14:24

标签: javascript orientdb

var g = orient.getGraph();

var sqlClassRecords =' select * from' + paramClass;

var listRecords = g.command(' sql',sqlClassRecords);

return listRecords;

上面的行提供了元数据加上out和in的值。就像这样:

[     {         " @ type":" d",         " @ rid":"#46:0",         " @ version":1,         " @ class":" relatedTo",         " out":"#28:1",         "在":"#28:2",         " @ fieldTypes":" out = x,in = x"     } ]

如何使用js函数获取此值(#28:1)和(#28:2)值。 listRecords [i] .getRecord()。field(" out")工作不正常。它给出顶点类和rids。我只想要rids。

1 个答案:

答案 0 :(得分:1)

你只需要添加另一个getRecord()。field()来获取它的rids:

var g = orient.getGraph();

var sqlClassRecords = 'select * from ' + paramClass;

var listRecords = g.command('sql',sqlClassRecords);

var result = [];

for(var i = 0; i < listRecords.length; i++)
{
    var out_ = listRecords[i].getRecord().field('out').getRecord().field('@rid').toString();
    var in_ = listRecords[i].getRecord().field('in').getRecord().field('@rid').toString();
    result.push(new Array("out: " + out_, "in: " + in_));
}

return result;