问题描述
我一直试图将数据从 elasticsearch 加载到组合框但没有成功,但是将数据从 json 文件加载到组合框它可以工作。
唯一不同的是,从存储加载数据到json文件,成功加载数据,但是对于elasticsearch,它回复'400:Bad Request'
[Json 文件]
[
{
"index":"color","_type":"_doc","_id":1,"_score":1.0,"_source":
{
"name":"Red"
}
},{
"index":"color","_id":2,"_source":
{
"name":"Blue"
}
}
]
[ElasticSearch Json 回复]
{
"took":3,"timed_out":false,"_shards":
{
"total":1,"successful":1,"skipped":0,"Failed":0
},"hits":{
"total":{
"value":4,"relation":"eq"
},"max_score":1.0,"hits":[
{
"_index":"color","_source":{
"name":"Red"
}
},{
"_index":"color","_source":{
"name":"Blue"
}
},"_id":3,"_source":{
"name":"Green"
}
},"_id":4,"_source":{
"name":"Yellow"
}
}
]
}
}
我的型号代码
Ext.define('MyApp.model.ColorModel',{
extend: 'Ext.data.Model',alias: 'model.colormodel,requires: [
'Ext.data.field.String','Ext.data.field.Integer'
],fields: [
{
type:'string',name:'_index'
},{
type:'string',name:'_type'
},name:'_id'
},{
type:'int',name:'_score'
},{
name:'_source'
},]
});
Ext.define('MyApp.store.ColorStore',{
extend: 'Ext.data.Store",requires: [
'MyApp.model.ColorModel','Ext.data.proxy.Ajax','Ext.data.reader.Json'
],constructor: function(cfg) {
var me = this;
cfg = cgf || {};
me.callParent([Ext.apply({
storeId:'ColorStore',model:'MyApp.model.ColorModel',proxy: {
type:'ajax',url: 'http://localhost:8888/data/color.json,withCredentials:true,reader: {
type:'json'
}
}
},cfg)]);
}
});
[从 elasticsearch 中检索的我的另一个商店] - 不工作
Ext.define('MyApp.store.ESColorStore',constructor: function(cfg) {
var me = this;
cfg = cgf || {};
me.callParent([Ext.apply({
storeId:'ESColorStore',proxy: me.processMyAjaxProxy1({
type:'ajax',read: function(operation,callback,scope){
var request = this.bulidRequest(operation,scope);
var query = {
"from": operation.params.from,"size": operation.params.size,"query": {
"query_string" : { }
},"sort": [
{
"name.raw":{
"order": "asc"
}
}
]
};
Ext.apply(request,{
headers: this.headers,timeout: this.timeout,scope: this,callback: this.createRequestCallback(request,operation,scope),method: 'POST',params: operation.params,jsonData: query,disableCaching:true,success: function(rec) {
console.log('[ESColorStore],successfully retrieved query: ' + rec.responseText);
}
failure: function(rec) {
console.log('[ESColorStore],Failed retrieved query: ' + rec.responseText);
}
});
Ext.Ajax.request(request);
return request;
},cfg)]);
},proccessMyAjaxProxy1: function(config) {
config.api = {
read: 'http://localhost:9200/color/_search'
};
config.url = 'http://localhost:9200/color/';
return config
},});
[查看次数]
Ext.define('MyApp.view.MyPanel',{
extend: 'Ext.Panel',alias: 'widget.mypanel',requires: [
'MyApp.view.MyPanelviewmodel','Ext.field.ComboBox'
],viewmodel: {
type: 'mypanel'
},title: 'My Panel',items: [
{
xtype:'comoboBox',name:'select-the-color',width: 419,docked: 'top',label:'Select The Color',autoLoadOnValue: true,displayField: '_source.name',selectOnTab:false,store:'ESColorStore',valueField:'_source.name',queryCaching: false,queryParam:''
}
]
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)