append - Methods - Assess API

Assess API Methods

append()

Append additional questions/features to the desired DOM element. The appended feature and question instances can then be stored and interacted with through feature instance public methods and question instance public methods respectively.

Examples

assessApp.append({
    // optional - if not set, additional questions/features will be appended
    // to the end of assess app's container
    "element": document.querySelector('.additional-widget-wrapper'),

    "features": [{
        "type": "calculator",
        "mode": "basic"
    }],

    "questions": [{
        "type": "plaintext"
    }]
}).then(function (data) {
    // suffixed with 0, 1, ...n if there are many features with the same "type"
    var newCalculatorInstance = data.features['calculator-0'];

    // suffixed with 0, 1, ...n if there are many questions with the same "type"
    var newPlaintextInstance = data.questions['plaintext-0'];

    // User now can interact with appended widgets through their public methods
    // Toggle visibility of current calculator instance
    newCalculatorInstance.toggle();
}).catch(function (error) {
    throw error;
});

Arguments

  • options object

    • element object

      A DOM element into which additional questions/features should be rendered. If no DOM element is provided, the created questions/features will be appended to the end of Assess API's container.

    • features array

      An array of feature configuration objects.

    • questions array

      An array of question configuration objects.

Return value

Type promise

  • then function

    Takes a success callback function that resolves the promise with an AppendData object as its parameter.

  • catch function

    Takes a rejection callback function that rejects the promise with an error as its parameter.

Type definitions

  • AppendData object

    An object containing question and feature objects that allow access to methods of each newly appended question and feature instance.

    • features AppendDataFeatures

    • questions AppendDataQuestions

  • AppendDataFeatures object

    An object containing Feature objects. Each FeatureObject will be prefixed with "[feature type]-[index of feature]", e.g. appendData.features['calculator-0'].

  • AppendDataQuestions object

    Each QuestionJson object will be prefixed with "[question type]-[index of question]", e.g. appendData.questions['shorttext-0'].

Was this article helpful?

Did you arrive here by accident? If so, learn more about Learnosity.