这就是我到目前为止所拥有的。搜索输入字段在 hbs 模板中渲染得很好。但当我开始输入时,什么也没有发生。我缺少什么?任何指示将不胜感激。
// ui/app/routes/application.js
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return Ember.RSVP.hash({
orders: this.store.find('order'),
products: this.store.find('product', { status: 'available' })
});
},
});
// ui/app/controllers/application.js
import Ember from 'ember';
export default Ember.ObjectController.extend({
products: function() {
console.log('adf');
if (this.get('search')) {
return this.get('searchedProducts');
} else {
return this.get('products');
}
}.property('search', 'searchedProducts'),
searchedProducts: function() {
var search = this.get('products').toLowerCase();
return this.filter(function(product) {
return product.get('name').toLowerCase().indexOf(search) !== -1;
});
}.property('search', '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0373716c67766077702d436662606b2d6d626e66" rel="noreferrer noopener nofollow">[email protected]</a>'),
});
// ui/app/templates/application.js
<br />{{input type="text" value="search" placeholder="search" class="search"}}
{{outlet}}
最佳答案
{{input type="text" value="search" placeholder="search" class="search"}}
表示您正在将字符串值'search'
分配给某个文本字段。那不是你想要的。您想要的是将 search
属性绑定(bind)到文本字段中输入的内容,如下所示:
{{input type="text" value=search placeholder="search" class="search"}}
看出区别了吗?
关于ember.js - 如何实现搜索框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27630767/