2014-01-15 113 views
2

如果与其他帖子非常相似,我会提前道歉,但是在完成一个多星期的工作后,我无法获得此功能。最后得到webservice返回数据,我可以看到返回的数据,但商店不会加载它。除了一种情况:当我创建一个ArrayStore并将商店设置为loadRawData时,我在网格中看到整个响应错误地全部显示在一列中;但很高兴看到数据。是否有人可以看看这个,看看为什么我的店不加载数据和填充网格:extjs ajax呼叫商店未加载

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”根目录是由我手动添加的,并不存在于原始web响应中。我抓住它,并添加根:

{"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"}, 

OK,我发现这可能是有问题ext.ajax.request调用。在发出请求时,商店甚至没有定义,因此数据没有加载。我怎么能通过这个?

+0

正确的方法是在存储上声明代理并加载存储。你的服务器响应是什么样的? –

回答

2

在这里,我会给你一个例子,只是比较你的代码。

// 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响应,您应该返回successfailure数据在json对象中。没有必要在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"}, 
+0

非常感谢详细的分解。我将我的代码改为一个简单的例子,将你的模板作为模板使用,但仍然没有。使用小提琴手我发现webservice甚至没有被调用。 – vbNewbie

+0

你认为这与异步调用有关:web服务返回的数据,但没有及时创建存储 – vbNewbie

+0

我已经使用了小提琴手,从我可以看到的是,甚至没有调用的URL;但它是有效的,如果我粘贴在浏览器 – vbNewbie

1

不是真的知道你如何在这样的状态下得到了自己。在SDK下载中有很多加载网格的例子。代理没有失败/成功的方法。

小提琴here。工作代码:

Ext.onReady(function() { 

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


    var store = new Ext.data.Store({ 
     model: 'User', 
     proxy: { 
      type: 'ajax', 
      url: 'data.json', 
      reader: { 
       type: 'json', 
       root: 'rules' 
      } 
     } 
    }); 
    store.load(); 

    var grid = new Ext.grid.Panel({ 
     renderTo: Ext.getBody(), 
     width: 400, 
     height: 400, 
     store: store, 
     columns: [{ 
      text: 'Value', 
      dataIndex: 'value', 
      flex: 1 
     }, { 
      text: 'Tag', 
      dataIndex: 'tag' 
     }] 
    }); 
}); 
+0

感谢您的回复。我终于想出了在使用链接之后关注实际的webservice,发现它必须是web服务,因为它仍然返回包含的内容,尽管它看起来像json 。我将contentType更改为json,但仍然没有想到。但至少它消除了extjs代码的问题。感谢您的其他建议。 – vbNewbie

+0

当时无法帮助您。祝你好运。 –