あなたの答えはおそらくうまくいくでしょう、しかしtbhは私にはあまりにも多くのクリックがありました。
これが私が最終的にそれをした方法です。cacheSubjectsは主な機能です。
var sgc_subjectCache = [];
var sgc_subjectCacheCount = 0;
function cacheSubjectsCallback(data) {
// update subjects
// loop through retrieved subjects and add to cache
for( i=0; i < data.length; i++ )
{
var subject = data[i];
subject.Root = subject.Title;
// var subjectid = subject.SubjectId;
sgc_subjectCache.push( subject );
sgc_subjectCacheCount += 1;
}
}
function cacheSubjectsComplete() {
// now update title with ancestors
var done = false;
while(done==false)
{
done = true;
// outer loop
var len = sgc_subjectCache.length;
for( var i=0; i < len-1; i++ )
{
subject = sgc_subjectCache[ i ];
// inner loop
for( var j=0; j < len-1; j++ )
{
subject2 = sgc_subjectCache[ j ];
if( subject.ParentSubject.Id === subject2.SubjectId )
{
// found the parent
var newTitle = subject2.Title + ' : ' + subject.Title;
sgc_subjectCache[ i ].Title = newTitle;
sgc_subjectCache[ i ].Root = subject2.Root;
sgc_subjectCache[ i ].ParentSubject.Id = subject2.ParentSubject.Id;
done = false; // more to do
}
}
}
}
}
function cacheSubjects() {
sgc_subjectCache = [];
var options = "$select=Title,SubjectId,ParentSubject";
SDK.REST.retrieveMultipleRecords("Subject", options, cacheSubjectsCallback, function(error) {
alert( error );
}, cacheSubjectsComplete);
}