Giter VIP home page Giter VIP logo

Comments (1)

PhiLhoSoft avatar PhiLhoSoft commented on August 24, 2024

This fix breaks when combined with mine, allowing to provide options as an object. Since the object doesn't have (likely) a splice() method, I get a TypeError.
I have a fix, tested in http://plnkr.co/edit/8OuwS7?p=preview on both cases (array and object, one on persons, the other on e-mails).
Note: it includes another change, related to #69, but they are distinct.

Basically: I rename generateOptions to normailzeOptions, because it changes the data in place.
Instead of return $.map(...); I do:

    angular.forEach(data, function(opt, key) {
        if (typeof opt === 'string') {
            data[key] = createItem(opt);
        }
    });
    return data;

When I have generateOptions(scope.ngModel) I replace it with normalizeOptions(angular.copy(scope.ngModel), ie. I do the copy on the call site.
Thus, the main change becomes:

  if (scope.options) {
    // replace string options with generated options while retaining a reference to the same array
    normalizeOptions(scope.options);
  } else {
    // default options = [ngModel] if no options specified
    scope.options = normalizeOptions(angular.copy(scope.ngModel));
  }

I can do a pull request with these changes if you want.

from angular-selectize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.