在sencha touch 1.1中加载要存储的复杂对象

Loading complex object to store in sencha touch 1.1

本文关键字:存储 复杂 对象 加载 sencha touch      更新时间:2023-09-26

我有一个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' }
       ]
});

希望这能帮助到一些人。