2014-07-19 36 views
0

我有分量Ext.dataView.DataView內鳴叫的列表。點擊列表中的一項,它會打開一個包含推文細節的容器。這個cointainer由工具欄(帶標題和後退按鈕)組成,包含推文信息和包含推文用戶位置的地圖。後退按鈕應該返回到列表但不工作。如何解決?煎茶觸摸2:數據視圖和後退按鈕不工作

這是一個代碼:

'TweetList'

Ext.define('TwitterSearch.view.TweetList', { extend: 'Ext.dataview.DataView', 
xtype: 'tweetlist', 
requires: [ 
    'TwitterSearch.view.TweetListItem', 
    'Ext.plugin.PullRefresh', 
    'Ext.plugin.ListPaging', 
    'TwitterSearch.view.contact.Show' 
], 


config: { 
    ui   : 'timeline', 
    defaultType : 'tweetlistitem', 
    allowDeselect: false, 
    useComponents: true, 
    emptyText: 'No tweets found.', 
    itemTpl: ['TwitterSearch.view.contact.Show'], 


    plugins: [ 
     'pullrefresh', 
     { 
      type: 'listpaging', 
      autoPaging: true 
     } 
    ], 


    items: [ 
     { 
      docked: 'top', 
      xtype : 'toolbar', 
      hidden: true, 
      ui : 'searchbar', 
      items: [ 
       { 
        xtype: 'button', 
        ui : 'back', 
        text : 'Searches' 
       } 
      ] 
     } 
    ] 
}, 
initialize: function(obj, eOpts) { 
    this.callParent(); 
    }}); 

'顯示別名TweetDetail'

Ext.define('TwitterSearch.view.contact.Show', { 
extend : 'Ext.Container', 
xtype : 'contact-show', 
requires: [ 'Ext.Map'], 


config : { 
    store: 'Tweet', 
    title : 'Information', 
    baseCls : 'x-show-contact', 
    layout : 'vbox', 
    items : [ 
      { 
      xtype: 'toolbar', 
      docked: 'top', 
      title: 'Tweets Detail', 

      items: [ 
        { 
         xtype: 'button', 
         text: 'Back', 
         ui: 'back', 
         id: 'tweetDetailBackButton' 
        } 
       ] 





      },{ 
       id : 'contenuto', 
       tpl : [ 
         '<div class="header">', 
         '<div class="avatar"><img src="../resources/images/default_profile_6_bigger.jpeg" /></div>',    
         '<h3>Nome: {nomeutente}</h3>', 
         '<h4>Tweet: {tweet} </h4>', 
         '</div>', 

         '<p>Descrizione:{descrizione}</p>', 
         '<p>Lingua:{lingua}</p>', 
         '<p>Et&#225:{eta}</p>', 
         '<p>Nazione:{country}, Citt&#225:{city}</p>', 
         //'<p>Nazione:{country}</p>',    
         //'<p>Citt&#225:{city}</p>', 
         '<p>Latitudine:{latitude},Longitudine:{longitude}</p>', 
         //'<p>Id Utente:{id_utente}</p>', 
         //'<p>Id Luogo:{id_luogo}</p>', 

         ].join('') 
      }, {  

       xtype: 'map', 
       id: 'dettaglio-map', 
       flex: 1, 
       mapOptions: { 
        zoomControl: true, 
        zoomControlOptions: { 
         style: google.maps.ZoomControlStyle.DEFAULT 
        }, 
        navigationControl: true, 
        navigationControlOptions: { 
         style: google.maps.NavigationControlStyle.DEFAULT 
        }, 
        panControl: true, 
        rotateControl: true, 
        streetViewControl: false, 
        mapTypeControl: true, 
        zoom: 12 
       }, 
       listeners: { 
        painted: function(map) { 
         record = map.getData(); 
        }, 

       } 
      } 
     ], 
     record: null 
}, 


updateRecord: function(newRecord) { 
    if (newRecord) { 
     this.down('#contenuto').setData(newRecord.data); 
     this.down('#dettaglio-map').setData(newRecord.data); 

     this.down('map').setMapCenter({ 
      latitude: newRecord.data.latitude, 
      longitude: newRecord.data.longitude 
     }); 

    var map = this.down('map').getMap(); 
     var marker = new google.maps.Marker({ 
      position: position = new google.maps.LatLng (newRecord.data.latitude,newRecord.data.longitude), 
      map: map, 
      title : 'Position = ' + position.toString() 
     }); 
     var infowindow = new google.maps.InfoWindow({ 
      content: marker.title 
     }); 



    marker.setMap(map); 

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

    } 
}}); 

'MainSearch' 搜索欄,SearchList組成和TweetList」

Ext.define('TwitterSearch.view.MainSearch', { 
extend: 'Ext.Container', 
xtype : 'mainsearch', 


requires: [ 
    'TwitterSearch.view.SearchBar', 
    'TwitterSearch.view.SearchList', 
    'TwitterSearch.view.TweetList' 
], 


config: { 
    fullscreen: true 
}, 
initialize: function(obj, eOpts) { 
    this.callParent(); 
    }}); 

和控制器...

Ext.define('TwitterSearch.controller.SearchController', { 
extend: 'Ext.app.Controller', 


config: { 
    refs: { 
     main: { 
      selector : 'mainview', 
      xtype  : 'mainview', 
      autoCreate: true 
     }, 
     searchBar: 'searchbar', 
     searchList: 'searchlist', 
     tweetList: 'tweetlist', 
     searchField: 'searchbar > searchfield', 
     showContact: 'contact-show',  
    }, 


    control: { 
     searchField: { 
      keyup: 'onSearch' 
     }, 


     tweetList: { 
      itemtap: 'onTweetTap' 
     }, 


     searchList: { 
      select: 'onSearchSelect', 
      itemswipe: 'onSearchSwipe' 
     }, 


     'searchlist searchlistitem button': { 
      tap: 'onSearchDelete', 
     }, 

     'contact-show button[ui=back]': { 
      tap: 'onBackButtonTap' 
     } 

     } 
}, 


launch: function() { 
    Ext.getStore('SearchesStore').load({ 
     callback: this.onSearchesStoreLoad, 
     scope: this 
    }); 
}, 


/** 
* Called when the searchesStore has been loaded from localStorage. If it is NOT a phone, it will select one of the searches 
* from the list, now that it is loaded. 
* We don't want to select a search when it is loaded on a phone, as it would trigger the tweetList view to display. 
*/ 
onSearchesStoreLoad: function() { 
    var search = Ext.getStore('SearchesStore').getAt(0); 
    if (!search) { 
     this.doSearch("%%"); 
    } 
}, 



/** 
* Called when a search is selected from the searchList. It sets the store of the tweetList to the tweets() store of the selected 
* search isntance. If the device is a phone, we set the active item to the tweetList. If it is now, we just ensure the tweetList 
* is visible 
*/ 
onSearchSelect: function(list, search) { 
    var store = search.tweets(); 


    this.getTweetList().setStore(store); 
    store.load(); 
}, 


/** 
* Called when an item in the searchList is swiped. It will show the delete button in the swiped item. 
*/ 
onSearchSwipe: function(dataview, index, target) { 
    if (Ext.getStore('SearchesStore').getCount() < 2) { 
     return; 
    } 


    //set the currentDeleteButton so we know what is it to hide it in the listener below 
    this.currentDeleteButton = target.getDeleteButton(); 
    this.currentDeleteButton.show(); 


    //add a listener to the body, so we can hide the button if the user taps anywhere but the button. 
    Ext.getBody().on('tap', this.onBodyTap, this); 
}, 


/** 
* Called when the user taps on the body. Hides the delete button and removes the listener from the body. 
*/ 
onBodyTap: function(e) { 
    if (this.currentDeleteButton) { 
     this.currentDeleteButton.hide(); 
    } 


    //remove the listener 
    Ext.getBody().un('tap', this.onBodyTap, this); 
}, 


/** 
* Called when a user taps on an item in the tweetList. This is used to check if the element the user tapped on is a hashtag. 
* If it is a hashtag, we get watchever that hashtag is and call {@link #doSearch} with it. 
* We could possibly extend this to users, too. 
*/ 
onTweetTap: function(list, index, target, record, e) { 
    target = Ext.get(e.target); 


    if (target && target.dom && target.hasCls('hashtag')) { 
     this.doSearch(target.dom.innerHTML); 
    } 
    else if (!this.showContact) { 
     this.showContact = Ext.create('TwitterSearch.view.contact.Show'); 
    } 
    this.showContact.setRecord(record); 


    if (!this.showContact.getParent()) { 
     //Ext.Viewport.removeAll(true,true); 
     Ext.Viewport.removeAt(0); 

     Ext.Viewport.add(this.showContact); 
    } 


    this.showContact.show(); 
}, 

onContactShow: function() { 
    Ext.getCmp('viewport').getLayout().getAnimation().setReverse(false); 
}, 



/** 
* Called when a use taps the delete button on a searchList item 
*/ 
onSearchDelete: function(button, e) { 
    var item = button.getParent(), 
     search = item.getRecord(); 


    this.fireAction('destroy', [search, button], 'doDestroy'); 
}, 


/** 
* Removes a specified search record from the searches store. The tablet controller subclass has some additional 
* logic to select the nearest saved search 
*/ 
doDestroy: function(search, button) { 
    var store = Ext.getStore('SearchesStore'); 


    store.remove(search); 
    store.sync(); 
    button.hide(); 
}, 


/** 
* Called on the keyup event of the search field. If the enter/return key was pressed, it will fire the search action. 
*/ 
onSearch: function(field, e) { 
    var keyCode = e.event.keyCode, 
     searchField = this.getSearchField(); 


    //the return keyCode is 13. 
    if (keyCode == 13) { 
     //fire the search action with the current value of the searchField 
     this.fireAction('search', [searchField.getValue()], 'doSearch'); 

    } 
}, 


/** 
* Called with the search action above. Searches twitter for a specified search term or record 
*/ 
doSearch: function(search) { 
    var model   = TwitterSearch.model.SearchModel, 
     tweetList  = this.getTweetList(), 
     searchList = this.getSearchList(), 
     searchesStore = Ext.getStore('SearchesStore'), 
     searchField = this.getSearchField(), 
     query, index; 


    // ensure there is a search... 
    if (!search) { 
     return; 
    } 


    //ensure the tweetlist is visible 
    tweetList.show(); 


    //check if ths search already exists in the searchesStore 
    index = searchesStore.find('query', search); 
    if (index != -1) { 
     //it exists, so lets just select it 
     search = searchesStore.getAt(index); 


     searchList.select(search); 


     //empty the field and blur it so it looses focus 
     searchField.setValue(''); 
     searchField.blur(); 


     return; 
    } 


    //if the passed argument is not an instance of a Search mode, create a new instance 
    if (!(search instanceof TwitterSearch.model.SearchModel)) { 
     query = search.replace("%20", " "); 
     search = new model({ 
      query: query 
     }); 
    } 


    this.scriviCookie('key', query, 100); 
    //scriviCookie('key', query, 100); 
    //String cookie = this.readCookie('key'); 
    var x = this.leggiCookie('key'); 
    alert ("Cookie = " + x); 





    //add the new search instance to the searchsStore 
    searchesStore.add(search); 
    searchesStore.sync(); 


    // select the new record in the list 
    searchList.select(search); 


    //empty the field and remove focus from it 
    searchField.setValue(''); 
    searchField.blur(); 
}, 

onBackButtonTap: function() { 
    this.getMain().setActiveItem(0); 
}, 

scriviCookie: function(nomeCookie,valoreCookie,durataCookie) 
{ 
    var scadenza = new Date(); 
    var adesso = new Date(); 
    scadenza.setTime(adesso.getTime() + (parseInt(durataCookie) * 60000)); 
    document.cookie = nomeCookie + '=' + escape(valoreCookie) + '; expires=' + scadenza.toGMTString() + '; path = /'; 
}, 


leggiCookie: function(nomeCookie) 
{ 
    if (document.cookie.length > 0) 
    { 
    var inizio = document.cookie.indexOf(nomeCookie + "="); 
    if (inizio != -1) 
    { 
     inizio = inizio + nomeCookie.length + 1; 
     var fine = document.cookie.indexOf(";",inizio); 
     if (fine == -1) fine = document.cookie.length; 
     return unescape(document.cookie.substring(inizio,fine)); 
    }else{ 
     return ""; 
    } 
    } 
    return ""; 
}}); 

因爲它可以解決這個問題嗎?

回答

0

我試圖用最小的設置代碼。只需使用TwitterSearch.view.contact.Show和TwitterSearch.controller.SearchController即可。按鈕水龍頭被控制器識別。 由於您沒有提供完整的代碼,我無法理解實際問題。

但我可以假設如下: 在您的onTweetTap中,您創建showContact視圖並使用數據填充它。之後,您嘗試從Ext.Viewport中刪除第一個項目,並將其替換爲您的showContact視圖。目前爲止沒有問題。但在您的onBackButtonTap中,您只會嘗試將主視圖的活動項目設置爲第一個元素。這不會影響視口。所以你不會回到列表中。至少我認爲這是你的嘗試。

我會建議使用Ext.navigation.View。該觀點將處理所有的轉變。所有你需要做的是推/流行的意見。你甚至不必擔心後退按鈕。導航視圖將爲您創建一個導航視圖並點擊它將自動返回到先前的視圖。

因此,所有你需要做的就是創建一個導航視圖,並把你的鳴叫名單進去。列表的select listener只需要創建一個show view,用記錄數據填充它並將其推入導航視圖。而已。

+0

我無法使用導航視圖,因爲數據視圖如此創建,它會將我們在部件服務器中找到的數據庫所發送的推文的所有信息帶到我的手中。tweetList由推文組成(包括@的轉推,以及所有連接到推文的鏈接)以及推文的名稱。點擊tweet,它打開DataView的組件DataItem,它引入了推文的所有信息,也包括地圖和tweet消費者所有者的座標。我參考了Sencha Touch的示例TouchTweets。 – tock

+0

我仍然不明白爲什麼你不能使用導航視圖。基本上它只是你所有其他容器周圍的另一個容器。數據來自哪裏並不重要。創建你的組件不會改變... – Martin

+0

...無論如何,正如我所說:這似乎是問題出在你的onTweetTap和onBackButtonTap方法。在你的onTweetTap方法中,你從Ext.Viewport中刪除第一個(也可能是唯一的)項目並添加showContact視圖。但是,您不要在onBackButtonTap中更改我們的Ext.Viewport視圖。您只設置主視圖的activeItem。這不影響視口。將主視圖添加到onBackButtonTap中的視口中。這可以做到這一點。 – Martin

0

我無法使用導航視圖,因爲創建的數據視圖會將我在發佈於零件服務器中的數據庫所採用的推文的所有信息都帶到我的手中。 tweetList由推文組成(包括@的轉推,以及所有連接到推文的鏈接)以及推文的名稱。點擊tweet,它打開DataView的組件DataItem,它引入了推文的所有信息,也包括地圖和tweet消費者所有者的座標。我參考了Sencha Touch的示例TouchTweets。那麼誰可以幫助我?

0

在onbackButtonTap我試圖與這些指令:Ext.Viewport.removeAt(0); Ext.Viewport.add(this.getMain);好吧,它可視化一個空的視圖。