在sencha touch 1.1中加载要存储的复杂对象
Loading complex object to store in sencha touch 1.1
我有一个json对象以下面的格式返回。
`{
"ParkingFacilities": [
{
"VendorID": 1200,
"FacilityID": 902,
"ParkingType": "Garage",
"BARTValidationRequired": null,
"LotName": "California and Steiner Lot",
"City": "San Francisco",
"Street": "2450 California Street",
"Neighborhood": "Fillmore",
"Latitude": "37.790000",
"Longitude": "-122.430000",
"Distance": "",
"Availability": "Space Available: <b>30%</b> (210/65) <br>Current Price: $8/hr-$35/hr max <br />Open Today:",
"Details": null,
"Hours": "",
"Entrance": "",
"Contact": "",
"TodayTimings": null,
"TotalParkingSpace": 45,
"AvailableParkingSpace": 16,
"OccupiedParkingSpace": 29,
"PercentFull": 64,
"Rendering": 2,
"OwnershipAgencyType": null
}
],
"ParkingZones": [
{
"ZoneID": 1,
"City": "San Francisco",
"Neighborhood": "Fisherman's Wharf",
"CentralLatitude": 37.80696471,
"CentralLongitude": -122.41867077,
"LocationDescription": "Leavenworth & Beach",
"Total": 197,
"Available": 45,
"Availability": "Space Available: <b>45%</b> (89/197)",
"Occupied": 89,
"Distance": "0.4 Miles",
"Rendering": 3
}
]
}`
我想知道我如何为这个json结构创建一个模型,然后使用它来渲染地图上的点。
Ext.regModel("parking.models.Facility", {
fields:
[
{ name: 'VendorID', type: 'int' },
{ name: 'FacilityID', type: 'int' },
{ name: 'ParkingType', type: 'string' },
{ name: 'BARTValidationRequired', type: 'auto' },
{ name: 'LotName', type: 'string' },
{ name: 'City', type: 'string' },
{ name: 'Neighborhood', type: 'string' },
{ name: 'Latitude', type: 'auto' },
{ name: 'Longitude', type: 'auto' },
{ name: 'Distance', type: 'auto' },
{ name: 'Availability', type: 'string' },
{ name: 'Details', type: 'string' },
{ name: 'Hours', type: 'auto' },
{ name: 'Entrance', type: 'string' },
{ name: 'Contact', type: 'auto' },
{ name: 'TodayTimings', type: 'auto' },
{ name: 'TotalParkingSpace', type: 'float' },
{ name: 'AvailableParkingSpace', type: 'float' },
{ name: 'OccupiedParkingSpace', type: 'float' },
{ name: 'PercentFull', type: 'auto' },
{ name: 'Rendering', type: 'int' },
{ name: 'OwnershipAgencyType', type: 'auto' }
]
});
Ext.regModel("parking.models.Zones", {
fields:
[
{ name: 'ZoneID', type: 'int' },
{ name: 'City', type: 'string' },
{ name: 'Neighborhood', type: 'string' },
{ name: 'CentralLatitude', type: 'auto' },
{ name: 'CentralLongitude', type: 'auto' },
{ name: 'LocationDescription', type: 'string' },
{ name: 'Total', type: 'float' },
{ name: 'Available', type: 'float' },
{ name: 'Availability', type: 'string' },
{ name: 'Occupied', type: 'float' },
{ name: 'Distance', type: 'auto' },
{ name: 'Rendering', type: 'int' }
]
});
我为停车场设施创建的商店:
parking.stores.parkingFacility = new Ext.data.Store({
model: 'parking.models.Facility',
proxy: {
type: 'ajax',
url: 'GetParkingFacilityByCity.json',
reader: {
type: 'json',
root: 'ParkingFacilities'
}
},
autoLoad:true
});
This is how i render it in my view
var map = new Ext.Map({
title: 'Map',
useCurrentLocation: true,
mapOptions: {
center: new google.maps.LatLng(37.381592, -122.135672),
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP,
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.DEFAULT
}
},
listeners: {
maprender: function (comp, map) {
var image = 'icon_blueP.png';
***data = parking.stores.parkingFacility;
for (var i = 0, ln = data.data.length; i < ln; i++) {
addMarkers(data.data.items[i], image);
}***
}
}
});
var addMarkers = function (data,image) {
var latLng = new google.maps.LatLng(data.get('Latitude'), data.get('Longitude'));
var marker = new google.maps.Marker({
map: map.map,
position: latLng,
icon:image
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
// setTimeout( function(){ map.panTo (position); } , 1000);
}
问题是,而不是创建2个单独的存储。我可以使用单个存储,然后在Google地图中渲染时使用单个存储来获取所有信息吗?
这是问题发生的地方
> ***data = parking.stores.parkingFacility;
> for (var i = 0, ln = data.data.length; i < ln; i++) {
> addMarkers(data.data.items[i], image);
> }***
我需要调用类似
的东西吗? data 2= parking.stores.zones
for (var i = 0, ln = data.data.length; i < ln; i++) {
addMarkers(data.data.items[i], image);
}
或者有没有更好的方法。谁能帮我拿样品吗?
谢谢一生
我的解决方案是创建一个类型为auto的数据存储,如下所示。
Ext.regModel("PF", {
fields:
[
{ name: 'ParkingFacilities', type: 'auto' },
{ name: 'ParkingZones', type: 'auto' }
]
});
希望这能帮助到一些人。
相关文章:
- 将作用域存储在JSON中
- 使用javascript存储变量的最安全方式
- 当图像转换为本地存储的DataURL时,EXIF被删除
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- 如何有效地将游戏数据存储在URL查询字符串中
- Ember.js-接口状态应该存储在哪里
- 如何解雇“;铁局部存储负载”;事件
- 本地存储中的字符串到字节数组转换
- 在Redux中,我应该在哪里编写复杂的异步流
- 从jQuery调用存储在Variable中的函数
- 推荐在JavaScript中执行存储为字符串的函数,而不是使用eval
- 如何在 jQuery 中存储复杂对象/Razor 中的数据属性
- AJAX/HTML如何存储复杂的数据
- 如何正确存储复杂的jquery选择器链以供重用
- 在sencha touch 1.1中加载要存储的复杂对象
- 在chrome.storage中存储一个复杂对象
- 如何更新“复杂”使用jQuery's .data()存储的数据
- 如何可靠地存储复杂的表单数据以供提交
- ExtJS存储和复杂对象
- 复杂的HTML工具提示(存储)-架构建议