Model 如何在Sencha中为来自服务器的Json响应编写模型和存储
这是来自服务器的json响应Model 如何在Sencha中为来自服务器的Json响应编写模型和存储,model,sencha-touch,extjs,sencha-touch-2,store,Model,Sencha Touch,Extjs,Sencha Touch 2,Store,这是来自服务器的json响应 {"class":"co.myapp.json.WsResponse","code":0,"message":"SUCCESS", "packet": {"class":"co.myapp.json.MyWantPacket","fullname":"Viswa","imageURI":"images/1.png","userid":1,"username":"viswa11","wantSuggestion":"learn g
{"class":"co.myapp.json.WsResponse","code":0,"message":"SUCCESS",
"packet":
{"class":"co.myapp.json.MyWantPacket","fullname":"Viswa","imageURI":"images/1.png","userid":1,"username":"viswa11","wantSuggestion":"learn guitar",
"wants":[{
"class" : "co.myapp.json.MyWant",
"id" : 2,
"replyCount" : 0,
"text" : "Message 2",
"time" : "Oct 3, 2012 - 14:59:02"
}, {
"class" : "co.myapp.json.MyWant",
"id" : 1,
"replyCount" : 2,
"text" : "Message 1",
"time" : "Oct 3, 2012 - 14:59:02"
}]
}}
我需要全名,imageuri,replayCount和上面jsone的文本
*这是我的型号
Ext.define('myApp.model.Wants', {
extend : 'Ext.data.Model',
config : {
fields : [
{ name : 'id', type : 'int'},
{ name : 'replyCount', type : 'int'},
{ name : 'text',type : 'string'},
{ name : 'wants',type : 'string'},
{ name : 'fullname',type : 'string'},
{ name : 'imageURI',type : 'string'}
{ name : 'time', type : 'string',dateFormat : 'D'}
]
}
});
*这是我的店铺
Ext.define('myApp.store.WantsStore', {
extend : 'Ext.data.Store',
config : {
model : 'myApp.model.Wants',
proxy : {
type : 'ajax',
url : http://127.0.0.1:8080/myapp/message/mwants?token=2143cede2ab147e6bc1cd5c7caa14792
reader : {
type : 'json',
rootProperty : 'packet'
}
},
sorters : [{
property : 'time',
direction : 'DESC'
}]
}
});
*这是我的数据视图列表(视图)
Ext.define('myApp.view.WantsList'{
扩展:“Ext.List”,
xtype:'wantslist',
配置:{
itemCls:“我的数据视图项”,
loadingText:“正在加载项…”,
emptyText:“未找到任何需求。”,
itemTpl:“{fullname}{replyCount}{text}{time}”
+“
”
}
});
如何更改模型、存储和视图**以便在DataViewList中显示全名、imageuri、replayCount和文本
我还想显示如下列表
图像全名replayCount文本时间(这是列表中的1项)
图像全名replayCount文本时间(这是列表中的2项)
图像全名replayCount文本时间(这是列表中的3项)
图像全名replayCount文本时间(这是列表中的4项)
……我认为您已经正确配置了CLASES,但JSon中的数据包属性必须是数组,否则您的存储中只能有一条记录。我的意思是:
{"class": "co.myapp.json.WsResponse",
"code":0,
"message":"SUCCESS",
"packet": [{
"class":"co.myapp.json.MyWantPacket",
"fullname":"Viswa",
"imageURI":"images/1.png",
...
请参阅数据包对象开头的[1]。我的问题是无法更改来自服务器的json
{"class": "co.myapp.json.WsResponse",
"code":0,
"message":"SUCCESS",
"packet": [{
"class":"co.myapp.json.MyWantPacket",
"fullname":"Viswa",
"imageURI":"images/1.png",
...