QScript DataFolder

From Q
Jump to navigation Jump to search

DataFolder

A folder in the data set tree, used to organize Question objects (variable sets) and other folders. Folders can nest to any depth and hold a mix of variable sets and subfolders.

dataFile

The DataFile object this folder belongs to.

deleteFolder()

Deletes this folder and everything in it: nested folders and their variable sets, matching deleting the folder in the user interface. Throws (deleting nothing) if any contained variable is used by a derived variable outside the folder. Contents that are referenced only by outputs are deleted without confirmation, and those outputs become invalid. To keep the contents, move them out first (e.g. with moveItemsAfter). Not called 'delete()' because that is a reserved word in JavaScript.

equals(obj)

Whether two objects are the same.
objThe object to compare against.
Returns:true or false
Example:
data_file.getQuestionByName('Q2').equals(data_file.questions()[0])

folders

Gets an array containing all the DataFolder objects in this container, including folders nested inside other folders, in tree order.

getItemByGuid(guid)

Finds a variable set or folder anywhere in this container (including inside nested folders) using its unique identifier.
guidThe item's identifier, as returned by its guid property.
Returns:The Question object or DataFolder object, or null if there is no such item in this container.

guid

Get the folder's internal unique identifier.

moveItemsAfter(to_move, after)

Moves variable sets and/or folders into this container. This is the standard folder-aware way to move items in the data set tree; variable sets always move as units, and folders move together with their contents. The items can come from anywhere in the same data file, so this covers moving into a folder, out of a folder (call it on the data file), and reordering within a container.
to_moveThe items to move. This should be an array of Question objects and/or DataFolder objects from this data file. A folder cannot be moved into itself or one of its own subfolders.
afterThe Question object or DataFolder object (a direct child of this container) after which the moved items are placed. null to move them to the top of this container.
Example:
demographics.moveItemsAfter([file.getQuestionByName('Age')], null);

name

Get/set the folder's name. Renaming throws if a sibling item already has that name.

newFolder(name, after)

Creates a new folder as a direct child of this container.
nameThe name for the new folder. There must not already be an item with this name in this container.
afterThe Question object or DataFolder object (a direct child of this container) after which the new folder is placed. null or omitted to place it at the end of this container.
Returns:The new DataFolder object.
Example:
var demographics = project.dataFiles[0].newFolder('Demographics');

parentFolder

The DataFolder object containing this folder, or null when this folder is at the top level of the data set tree.

questions

Gets an array containing all the Question objects (variable sets) in this folder, including those inside nested folders. The first question is [0].

subItems

Gets the direct children of this container, Question objects (variable sets) and DataFolder objects, in display order. Check each item's type, which is 'Question' or 'Folder', to tell them apart.
Example:
project.dataFiles[0].subItems.forEach(function(item) {
    log(item.type + ': ' + item.name);
});

type

Returns 'Folder'.