来自Sencha Touch 2商店的Magento-REST的嵌套JSON响应

时间:2012-09-04 09:59:34

标签: json rest sencha-touch-2 magento-1.7

我很难使用我的产品商店的代理来回应magento 1.7

响应如下:

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

但是,sencha(我认为)的预期输入应该是这样的:

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

如何更改代理的行为以便能够将加载的数据存储到我的商店中?

非常感谢提前!

1 个答案:

答案 0 :(得分:1)

要自定义您自己的回复,您必须继承Ext.data.reader.Reader 阅读器或在您的情况下,Sencha的模型/代理/存储接受Json类将响应中的数据转换为结果集。

干杯,奥列格

添加

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

比后来读者更多参考:'magentojson'

并保留对'json'读者的原始引用!