我有一个vuejs脚本,需要使用elasticsearch api方法.
// ./main.js
var Vue = require('vue');
Vue.use(require('vue-resource'));
import ES from './elasticsearch.js';
new Vue({
el: 'body',
methods: {
search: function() {
// should call the es.search...
}
}
});
Run Code Online (Sandbox Code Playgroud)
和弹性搜索脚本:
// ./elasticsearch.js
var es = require('elasticsearch');
var client = new es.Client({
host: 'localhost:9200'
,log: 'trace'
});
client.search({
index: 'my_index',
type: 'my_type',
body: {
fields: {},
query: {
match: {
file_content: 'search_text'
}
}
}
}).then(function (resp) {
var hits = resp.hits.hits;
}, function (err) {
console.trace(err.message);
});
Run Code Online (Sandbox Code Playgroud)
因此,在方法搜索 …
我正在努力尝试使用orderBy与vuejs 2.0上的filterBy,以及我发现的关于这个主题的所有研究,以及我问题底部的链接.
这是我的过滤器,它正在工作:
// computed() {...
filteredResults() {
var self = this
return self.results
.filter(result => result.name.indexOf(self.filterName) !== -1)
}
Run Code Online (Sandbox Code Playgroud)
组件中调用的方法:
// methods() {...
customFilter(ev, property, value) {
ev.preventDefault()
this.filterBook = value
}
Run Code Online (Sandbox Code Playgroud)
在组件中:
// Inside my component
<a href="#" @click="customFilter($event, 'name', 'Name..')">Name..</a>
Run Code Online (Sandbox Code Playgroud)
另一个过滤器,也可以:
// computed() {...
orderByResults: function() {
return _.orderBy(this.results, this.sortProperty, this.sortDirection)
}
Run Code Online (Sandbox Code Playgroud)
为了遵守我的订单我有这个方法:
// methods() {...
sort(ev, property) {
ev.preventDefault()
if (this.sortDirection == 'asc' && this.sortProperty == property ) {
this.sortDirection = 'desc' …Run Code Online (Sandbox Code Playgroud)