2012-09-04 34 views
1

我使用的是從Magento的未來1.7嵌套JSON響應從Magento的-REST在煎茶觸摸2的商店

的響應的響應我的產品,店內的代理不好受看起來是這樣的:

{ 
"1": 
    {"entity_id":"1","type_id":"simple","sku":"dress_test","status":"1","visibility":"4","tax_class_id":"2","weight":"1.0000","price":"1500.0000","special_price":"1000.0000","name":"Wedding dress","url_key":"dress","country_of_manufacture":"AO","msrp_display_actual_price_type":"2","gift_message_available":"1","news_from_date":"2012-03-21 00:00:00","news_to_date":"2012-03-24 00:00:00","special_from_date":"2012-03-21 00:00:00","special_to_date":"2012-03-24 00:00:00","description":"White wedding dress"}, 
"2": 
    {"entity_id":"2","type_id":"simple","sku":"black_sunglasses","status":"1","visibility":"4","tax_class_id":"2","weight":"0.2000","price":"500.0000","special_price":"300.0000","name":"Sunglasses","url_key":"sunglasses","country_of_manufacture":"AR","msrp_display_actual_price_type":"2","gift_message_available":null,"news_from_date":null,"news_to_date":null,"special_from_date":"2012-03-21 00:00:00","special_to_date":"2012-03-24 00:00:00","description":"Black sunglasses"} 
} 

但是從煎茶(我認爲)預計輸入應該是這樣的:

{ 
{"entity_id":"1","type_id":"simple","sku":"dress_test","status":"1","visibility":"4","tax_class_id":"2","weight":"1.0000","price":"1500.0000","special_price":"1000.0000","name":"Wedding dress","url_key":"dress","country_of_manufacture":"AO","msrp_display_actual_price_type":"2","gift_message_available":"1","news_from_date":"2012-03-21 00:00:00","news_to_date":"2012-03-24 00:00:00","special_from_date":"2012-03-21 00:00:00","special_to_date":"2012-03-24 00:00:00","description":"White wedding dress"}, 
{"entity_id":"2","type_id":"simple","sku":"black_sunglasses","status":"1","visibility":"4","tax_class_id":"2","weight":"0.2000","price":"500.0000","special_price":"300.0000","name":"Sunglasses","url_key":"sunglasses","country_of_manufacture":"AR","msrp_display_actual_price_type":"2","gift_message_available":null,"news_from_date":null,"news_to_date":null,"special_from_date":"2012-03-21 00:00:00","special_to_date":"2012-03-24 00:00:00","description":"Black sunglasses"} 
} 

如何更改代理的行爲,能夠加載的數據存儲到我的店嗎?

非常感謝提前!

+0

json示例(如sencha所預期的)看起來不像一個有效的json。 – Sark

回答

1

要定製您自己的回覆,您必須子類Ext.data.reader.Reader 閱讀器或在您的情況下Json類將響應中的數據轉換爲結果集的數據被Sencha的Model/Proxy/Store接受。

乾杯,奧列格

添加

Ext.define('lib.data.reader.Json', { 
    extend: 'Ext.data.reader.Json', 
    alias : 'reader.magentojson', ... 
}) 

不是使用對讀者日後參考: 'magentojson'

和你保持原有的參考 'json的' 讀者!

+0

這是工作,但: 現在我需要兩個版本的工作。一個商店的_normal_ sencha版本和另一個商店的我的_extended_版​​本。 但我只能實現_normal_或_extended_。 'Ext.define( 'lib.data.reader.Json',{ 延伸: 'Ext.data.reader.Json', 別名: 'reader.json', ... });' –

+0

得到它計算出: '讀者:{ type:'magentojson', rootProperty:'items' }'需要引用_extended_類 –