Javascript senchatouch中的JSON数据
我目前正在使用Sencha Touch,我正在尝试使用JSON视图从drupal安装中获取数据。我看过Sencha API文档,但无法使其正常工作 我的Json响应如下:Javascript senchatouch中的JSON数据,javascript,json,model-view-controller,extjs,Javascript,Json,Model View Controller,Extjs,我目前正在使用Sencha Touch,我正在尝试使用JSON视图从drupal安装中获取数据。我看过Sencha API文档,但无法使其正常工作 我的Json响应如下: { "spots" : [ { "spot" : { "nid" : "10", "created" : "1288868246", "title" : "Almanarre", "type" : "spot", "city
{
"spots" : [
{
"spot" : {
"nid" : "10",
"created" : "1288868246",
"title" : "Almanarre",
"type" : "spot",
"city" : "Hyères",
"country" : "fr",
"latitude" : "43.083433",
"longitude" : "6.148224"
}
},
{
"spot" : {
"nid" : "11",
"created" : "1288956341",
"title" : "Lac de Neuchâtel",
"type" : "spot",
"city" : "Dakhla",
"country" : "ma",
"latitude" : "23.866295",
"longitude" : "-15.738344"
}
},
{
"spot" : {
"nid" : "12",
"created" : "1288958572",
"title" : "Zurich",
"type" : "spot",
"city" : "Zurich",
"country" : "ch",
"latitude" : "0.000000",
"longitude" : "0.000000"
}
},
{
"spot" : {
"nid" : "13",
"created" : "1289302233",
"title" : "Berne",
"type" : "spot",
"city" : "Berne",
"country" : "ch",
"latitude" : "46.947999",
"longitude" : "7.448148"
}
},
{
"spot" : {
"nid" : "14",
"created" : "1290266721",
"title" : "Dakhla",
"type" : "spot",
"city" : "Rio de Janeiro",
"country" : "br",
"latitude" : "-22.903539",
"longitude" : "-43.209587"
}
},
{
"spot" : {
"nid" : "15",
"created" : "1299172773",
"title" : "Paje",
"type" : "spot",
"city" : "Paje",
"country" : "tz",
"latitude" : "-6.265646",
"longitude" : "39.535332"
}
}
]
}
和我的型号/商店/列表:
Ext.regModel( 'Spot', {
idProperty: 'id',
fields : [
{ name: 'id', type: 'int'},
{ name: 'date', type: 'date', dateFormat: 'c' },
{ name: 'title', type: 'string'},
{ name: 'type', type: 'string'},
{ name: 'country', type: 'string'},
{ name : 'city', type: 'string' },
{ name : 'lat', type: 'string' },
{ name: 'long', type: 'string'}
]
}); // Model
Ext.regStore('spotStore', {
model: 'Spot',
proxy: {
type: 'ajax',
url: '/api/spots/',
reader: {
type: 'json',
root: 'spots'
},
autoload: true
}
});
ks.views.spotsList = new Ext.List({
id: 'spotsList',
store: 'spotStore',
itemTpl: '<div class="list-item-title">{title}</div>' + '<div class="list-item-narrative">{country}</div>',
onItemDisclosure: function(record){
},
listeners: {
'render': function (thisComponent) {
thisComponent.getStore().load();
}
}
});
Ext.regModel('Spot'{
idProperty:“id”,
字段:[
{name:'id',type:'int'},
{name:'date',type:'date',dateFormat:'c'},
{name:'title',type:'string'},
{name:'type',type:'string'},
{name:'country',键入:'string'},
{name:'city',键入:'string'},
{name:'lat',type:'string'},
{name:'long',type:'string'}
]
}); // 模型
Ext.regStore('spotStore'{
型号:Spot,
代理:{
键入:“ajax”,
url:“/api/spots/”,
读者:{
键入:“json”,
根:“斑点”
},
自动加载:正确
}
});
ks.views.spotsList=新的外部列表({
id:“spotsList”,
商店:“spotStore”,
itemTpl:“{title}”+“{country}”,
OSCLOSURE:功能(记录){
},
听众:{
“呈现”:函数(thisComponent){
thisComponent.getStore().load();
}
}
});
调用后,它将创建一个包含6个项目的精确数字的列表。但是我不能让itemTpl
中的变量显示出来
有什么想法吗
非常感谢 问题在于您在创建存储时提到的根变量。我建议对Json格式进行一些更改 即 希望它能帮助
{
"spots": [
{
"nid": "10",
"created": "1288868246",
"title": "Almanarre",
"type": "spot",
"city": "Hyères",
"country": "fr",
"latitude": "43.083433",
"longitude": "6.148224"
},
{
"nid": "11",
"created": "1288956341",
"title": "Lac de Neuchâtel",
"type": "spot",
"city": "Dakhla",
"country": "ma",
"latitude": "23.866295",
"longitude": "-15.738344"
},
{
"nid": "12",
"created": "1288958572",
"title": "Zurich",
"type": "spot",
"city": "Zurich",
"country": "ch",
"latitude": "0.000000",
"longitude": "0.000000"
},
{
"nid": "13",
"created": "1289302233",
"title": "Berne",
"type": "spot",
"city": "Berne",
"country": "ch",
"latitude": "46.947999",
"longitude": "7.448148"
},
{
"nid": "14",
"created": "1290266721",
"title": "Dakhla",
"type": "spot",
"city": "Rio de Janeiro",
"country": "br",
"latitude": "-22.903539",
"longitude": "-43.209587"
},
{
"nid": "15",
"created": "1299172773",
"title": "Paje",
"type": "spot",
"city": "Paje",
"country": "tz",
"latitude": "-6.265646",
"longitude": "39.535332"
}
]
}