Answer the question
In order to leave comments, you need to log in
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
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?
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 questionAsk a Question
731 491 924 answers to any question