Skip to content

Flapjack should accept changes to the tree #8

Description

@jamesarosen

For example, a periodic poller might do an AJAX call for updates, then tell Flapjack to change the tree.

Option 1: use calls directly on the Flapjack instance

var aFlapjack = ...;
function doPoll() {
  $.ajax({
    ...
    success: function(data) {
      var group = aFlapjack.findOrCreateGroup(...);
      group.push(...);
    }
  });
}

Option 2: use events on the <select> and pass data:

function doPoll() {
  $.ajax({
    ...
    success: function(data) {
      $('#some_select').trigger('data-change.flapjack'), data);
    }
  });
}

Option 3: add DOM elements to the <select>:

function doPoll() {
  $.ajax({
    ...
    success: function(data) {
      var newOption = $("<option value='" + data.value + "'>" + data.text + "</option>");
      $('#some_select')
        .append(newOption)
        .trigger('data-added.flapjack', newOption);
    }
  });
}

Option 3 has the disadvantage that it's not necessarily compatible with a customer <select> parser -- although I suppose if the programmer is customizing the parser, she could compensate in the rendering of the new <option> or <optgroup>.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions