[Guide] Require empty check?


#1

I am following ember.js 2.3.0 guide.

now I read and code autocomplete method. https://guides.emberjs.com/v2.3.0/tutorial/autocomplete-component/

In this page, app/controller/index.js make undefined error when empty input string.

I don’t want to leave it.

So.

is it right code to solve? I find Ember.isEmpty().

export default Ember.Controller.extend({
  filteredList: null,
  actions: {
    autoComplete(param) {
      if(param !== "") {
        this.store.query('rental', {city: param}).then((result) => {
          this.set('filteredList',result);
        });
      }
      else {
        let filteredList = this.get('filteredList');
        if(Ember.isEmpty(filteredList)) {
          return;
        }
        console.log();
        this.set('filteredList').clear();
      }
    },
    search(param) {
      if(param !== "") {
        this.store.query('rental', {city: param}).then((result) => {
          this.set('model',result);
        });
      }
      else {
        let model = this.get('model');
        if(Ember.isEmpty(model)){
          return;
        }
        this.set('model').clear();
      }
    }
  }
});

I want to know someone who have elegant solution.


#2

Empty checks can be done with Ember.isEmpty() or Ember.isBlank()

Where Ember.isEmpty returns false for ({}) and isBlank will return true. So while handling objects try to use isBlank method


#3

Thanks @Sarath :slight_smile:

I’ll try Ember.isBlank()