0

大家好,我发现很难设置回调函数,我有一个列表,在我的控制器中,我正在尝试收听列表中的每个项目,以便在录制每个项目后,它会显示一个带有指向我商店中为该特定项目指定的指定纬度和日志的标记。我在想一个 itemtap 甚至会是最好的,但我不知道如何在我的控制器中设置它。

这是我的商店:

Ext.define('List.store.Presidents', {
extend : 'Ext.data.Store',

config : {
    model : 'List.model.President',
    sorters : 'lastName',
    storeId: 'contactmap',
    grouper : function(record) {
        return record.get('lastName')[0];
    },

    data : [{
        firstName : "Ikhlas HQ",
        lastName : "Tower 11A, Avenue 5, Bangsar South, No.8 Jalan Kerinchi 59200 Kuala Lumpur",
        lat : 3.110649,
        lng : 101.664991,
        id: '200',
    },
    {
        firstName : "PEJABAT WILAYAH SELANGOR",
        lastName : "No. 97, 97-1 & 97-2, Jalan Mahogani 5/KS7, Ambang Botanic, 41200 Klang, Selangor",
        lat : 3.003384,
        log : 101.45256,
        id: '001',
    },]}
});

这是我的控制器:

Ext.define('List.controller.Main', {
extend: 'Ext.app.Controller',
config: {
    refs: {
        main: 'mainpanel',
      },
    control: {
        'presidentlist': {
            disclose: 'showDetail'
        },
     } },
showDetail: function(list, record) {
            this.getMain().push({
                xtype: 'presidentdetail',
                title: record.fullName(),
                data: record.getData(),
listeners: {
    itemtap : function(component, map, geo, eOpts) {
                     var contactmap = Ext.getStore('contactmap'); 

                contactmap.load({ 
                    callback:function(records,map,componet,lad,log){
                        var position = new google.maps.LatLng(); 
                 }
                 var marker = new google.maps.Marker({
                    position: position,
                    map: map
                        });

                var infowindow = new google.maps.InfoWindow({
                    content: 'Working Fine'
                        });

            google.maps.event.addListener(marker, 'click', function() {
                    infowindow.open(map, marker);
                        });
                });

                },
              }, 
        })
     },
});

希望我能在这里得到一些帮助以继续我在这一点上被困住了。谢谢

4

2 回答 2

0
Ext.define('List.controller.Main', {
extend: 'Ext.app.Controller',
config: {
    refs: {
        myList: 'presidentlist', // 'presidentlist' is xtype of your list
      },
    control: {
        myList: {
            itemtap: 'onMyListItemTap'
        },
     }
},
onMyListItemTap: function(list, index, target, record, e, eOpts) {
  // some functionality here
  var myLat = record.data.lat;  // etc.
  var myLng = record.data.lng;  // etc.
}
于 2012-06-08T09:13:59.797 回答
0

我的控制器:

Ext.define('List.controller.Main', {
extend: 'Ext.app.Controller',
config: {
refs: {
    main: 'mainpanel',
  },
control: {
    myList: {
        itemtap: 'onMyListItemTap'
    },
    'presidentlist': {
            disclose: 'showDetail'
        },
 }
},
showDetail: function(list, record) {
            this.getMain().push({
                xtype: 'presidentdetail',
                title: record.fullName(),

onMyListItemTap: function(list, index, target, record, e, eOpts) {
    var position = new google.maps.LatLng();

    var myLat = record.data.lat;  
    var myLng = record.data.lng;

    var marker = new google.maps.Marker({
                    position: position,
                    map: map
                        });

google.maps.event.addListener(marker, 'click', function() {
                    infowindow.open(map, marker);
                        });

                    setTimeout(function() {
                    map.panTo(position);
                        }, 1000);
},
});
 },
});

我的店铺:

Ext.define('List.store.Presidents', {
extend : 'Ext.data.Store',

config : {
    model : 'List.model.President',
    sorters : 'lastName',
    storeId: 'contactmap',
    grouper : function(record) {
        return record.get('lastName')[0];
    },

    data : [{
        firstName : "Ikhlas HQ",
        lastName : "Tower 11A, Avenue 5, Bangsar South, No.8 Jalan Kerinchi 59200 Kuala Lumpur",
        lat : 3.110649,
        log : 101.664991,
        id: '200',
    },
    {
        firstName : "PEJABAT WILAYAH SELANGOR",
        lastName : "No. 97, 97-1 & 97-2, Jalan Mahogani 5/KS7, Ambang Botanic, 41200 Klang, Selangor",
        lat : 3.003384,
        log : 101.45256,
        id: '001',
    }, {
        firstName : "PEJABAT WILAYAH KEDAH",
        lastName : "57, Jalan Lagenda 3, Legenda Heights, 08000, Sungai Petani, Kedah Darul Aman",
        lat : 5.657754,
        log : 100.50014,
        id: '002',
    },] 
},
});

我的模型:

Ext.define('List.model.President', {
extend : 'Ext.data.Model',
config : {
    store: 'Presidents',
    fields : ['firstName', 'middleInitial', 'lastName', 'lat', 'log', 'id']
},
fullName : function() {
    var d = this.data, names = [d.firstName, (!d.middleInitial ? "" : d.middleInitial + "."), d.id];
    return names.join(" ");
}
});
于 2012-06-10T06:23:46.880 回答