F
F
fsamorodov2015-11-30 11:02:52
Ember.js
fsamorodov, 2015-11-30 11:02:52

How to find all matches in the database by string fragment in Ember 2.0?

Hello!
I'm trying to find all matches in the database for a piece of a phrase.
this.store.query("unit", {title: searchText})
Tell me what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Romanov, 2015-11-30
@fsamorodov

You are not asking the question that way. So no one will answer it.
This line forms a request to the backend like this:
And expects the backend to return a set of models that match the title parameter. Correctly accept the request, process and return. And that's all.
What is not working for you?

F
fsamorodov, 2015-11-30
@fsamorodov

I'm trying to implement autocomplete. It looks like this:

//контроллер
  phrase: '',
  loadData: function() {
    var searchText = this.get("phrase");
    var controller = this;
    if(searchText.length > 0) {
    this.set("searchResults", Ember.A() );
    this.store.query("unit", {title: searchText}).then(    //не понимаю как искать по кусочку фразы 
      function(data) {
        controller.get('searchResults').addObjects( data );
      },
      function(data) {
        alert('rejected, probably syntax error!');
      }
    );
    }
  }.observes("phrase"),
  searchResults: Ember.A()

//вьюха
    {{input type="text" value=phrase placeholder="Add words to your drill"}}
    <ul>
      {{#each searchResults as |result|}}
        <li>{{result.title}}</li>
      {{/each}}
    </ul>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question