gpt4 book ai didi

javascript - extjs ajax 调用存储未加载

转载 作者:行者123 更新时间:2023-11-29 19:44:04 25 4
gpt4 key购买 nike

如果与其他帖子非常相似,我提前道歉,但我已经工作了一个多星期后无法让它工作。终于让 web 服务返回数据,我可以看到返回的数据,但商店不会加载它。除了一种情况:当我创建一个 ArrayStore 并将存储设置为 loadRawData 时,我看到网格中的整个响应错误地全部显示在一列下;但很高兴看到数据。有人可以看看这个,看看为什么我的商店没有加载数据和填充网格:

   Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{ name: 'connTime', type: 'string' },
{ name: 'userName', type: 'string' },
{ name: 'clientName', type: 'string' },
{ name: 'feedUrl', type: 'string' },
{ name: 'dconnTime', type: 'string' },
{ name: 'errMessage', type: 'string' },
{ name: 'ip', type: 'string' }
]
});

var myStore = Ext.create('Ext.data.Store', {
model: 'User'
});


Ext.Ajax.request({
url: 'http://dfsdfsfsfs/WCFService/WebService1.asmx/getValue',
method: 'GET',
success: function (response, options) {
var s = response.responseText;
Ext.MessageBox.alert(s, 'WOO WOO');
myStore.loadData(s);
},
failure: function (response, options) {
Ext.MessageBox.alert('FAILED MF', 'Unable to GET');
}
});



var grid = Ext.create('Ext.grid.Panel', {
store: myStore,
stateful: true,
stateId: 'stateGrid',
columns: [
{
text: 'Query',
width: 25,
sortable: false,
dataIndex: 'userName'
},
{
text: 'Count',
width: 5,
sortable: true,
renderer: change,
dataIndex: 'ip'
},
{
text: 'Last Updated',
width: 76,
sortable: true,
dataIndex: 'connTime'
},
{
text: 'Disconnect Time',
width: 10,
sortable: true,
renderer: change,
dataIndex: 'dconnTime'
},
{
text: 'Client',
width: 10,
sortable: true,
renderer: change,
dataIndex: 'clientName'
}

],
height: 350,
width: 800,
title: 'Active Queries',
renderTo: 'grid-example',
viewConfig: {
stripeRows: true
}
});

.....

我什至尝试了一种不同的方式来做到这一点,而使用这种方式我什至没有看到返回的 ajax 响应:

 var newStore = Ext.create('Ext.data.ArrayStore', {
model: 'User',
proxy: {
type: 'ajax',
url: 'http://dfsdfsfsfs/WCFService/WebService1.asmx/getValue',
reader: {
type: 'json',
root: 'd',
successProperty: 'success'
},
success: function (response, options) {
var s = response.responseText;
Ext.MessageBox.alert(s, 'LA LA LA');
newStore.loadData(s);
},
failure: function (response, options) {
Ext.MessageBox.alert('FAILED AGAIN', 'SUCKS');
}
}
});

编辑:

服务器响应:

{"d":{"connTime":null,"userName":"101591196589145","clientName":null,
"feedUrl":null,"dconnTime":null,"errMessage":null,"ip":null}}

“d”root 是我手动添加的,原始 webresponse 中不存在。我捕获它并添加根:

{"connTime":null,"userName":"101591196589145","clientName":null,"feedUrl":null,
"dconnTime":null,"errMessage":null,"ip":null}}

编辑 2:

  Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{ name: 'value', type: 'string' },
{ name: 'tag', type: 'string' }
]
});


var newStore = new Ext.data.JsonStore({
model: 'User',
proxy: {
type: 'ajax',
url: 'http://localhost:52856/WCFService/WebService1.asmx/getRules',
reader: {
type: 'json',
root: 'rules',
idProperty: 'value'
},
success: function (response, options) {
var s = response.responseText;
Ext.MessageBox.alert(s, 'LA LA LA');
newStore.loadData(s);
},
failure: function (response, options) {
Ext.MessageBox.alert('FAILED AGAIN', 'SUCKS');
}
}
});

var grid = Ext.create('Ext.grid.Panel', {
store: newStore,
stateful: true,
columns: [

这是我正在尝试的新 json:

{"rules":[{"value":"101591196589145","tag":"16"},
{"value":"102890809752267","tag":"16"},
{"value":"107821192690513","tag":"16"}, {"value":"111517428886211","tag":"16"},
{"value":"117389718398171","tag":"16"},{"value":"12099149051","tag":"16"},

好的,我发现了 ext.ajax.request 调用可能存在的问题。在发出请求时,商店甚至没有定义,因此数据没有加载。我怎样才能克服这个问题?

最佳答案

这里我给大家举个例子,和你的代码对比一下就可以了。

// defining a model
Ext.define('SampleModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'YOUR_ID', type: 'int'},
{name: 'YOUR_NAME', type: 'string'}
]
});

// defining a store
var storeDefinition = new Ext.data.JsonStore({
model: 'SampleModel',
proxy: {
type: 'ajax',
url: '/your/url/path/data.php',
reader: {
// you MUST define root and idProperty
type: 'json',
root: 'rootList',
idProperty: 'YOUR_ID'
}
}
});

这里重要的部分是rootidProperty。正如您指定的那样,rootjson 对象的根节点。 idProperty是json对象中的唯一id。

要捕获successfailure 响应,您应该在json 对象中返回successfailure 数据。不必在 reader 部分指定 success 属性。例如;

public function dnr_info()
{
$dnr = $this->input->get('dnr', TRUE);
$subsys = $this->input->get('subsys', TRUE);
$data['success'] = TRUE;
$data['data'] = $this->dnr->get_dnr_info($dnr, $subsys);
echo json_encode($data);
}

以上函数将返回 json 对象的 success 属性。

并且,这是从服务器返回的 json 对象。

{"success":true,"data":{"SUBSYS_ART_NR":"136451","ART_NR":"459993","ACTION_DESC":"BAKKAL AKT\u0130V\u0130TES\u0130 (176)","ACTIONS_NR":"130012676","START_DATE":"19.12.2013","STOP_DATE":"16.01.2014","DISCOUNT_TYPE":"SPECIAL PRICE","LEVEL_TYPE":"QUANTITY","LEVEL_IMPACT":"MULTIPLE","BASIS":"ARTICLE","LEVEL_1":"1 ADET","VALUE_1":"5,92","NWW_VK_PREIS":"6.69","KOLLI_VK_PREIS":"6.69"}}
// here is the another sample for root which is articleList, idProperty which is ARTICLE_ID 
{"articleList":[{"ARTICLE_ID":"193","ART_NR":"225","ART_DESC":"27*1\/5LT.M.NEK.TAMEK.","SORTEN_TEXT":"ELMA","VAR":"1","GEBI":"1","SUBSYS_ART_NR":"225","NWW_VK_PREIS":"14.49","KOLLI_VK_PREIS":"14.49","DNR_ID":null,"STATUS":"0"},

关于javascript - extjs ajax 调用存储未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21150304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com