2014-02-23 21 views
1

我正在嘗試使用Ext.dataview.component.ListItemsencha touch 2.3(使用sencha架構師)中創建列表。我能夠通過使用updateRecord方法從商店中獲取值,但是我無法將其傳回主要組件。Sencha 2.3中使用架構師的DataView組件列表項

這就是我想實現: -

我想創建其文本將被從商店的動態顯示,如果用戶點擊它,它應該表現出與年齡報警按鈕的列表。我有一個名字和年齡的商店。我能夠得到的名字,但我不能得到警報setup.I需要用但─ 幫助這裏是我的數據視圖

Ext.define('MyListItem.view.MyListItem', { 
extend: 'Ext.dataview.component.ListItem', 
alias: 'widget.mylistitem', 

requires: [ 
    'Ext.Button', 
    'Ext.MessageBox' 
], 

config: { 
    padding: 10, 
    layout: 'hbox', 
    items: [ 
     { 
      xtype: 'button', 
      handler: function(button, e) { 
       var record = this.getRecord(); 
       console.log("buttonTapped"); 
       console.log(record); 
       Ext.Msg.alert(
       record.get('name'), // the title of the alert 
       "The age of this person is: " + record.get('age') // the message of the alert 
       ); 
      }, 
      text: 'MyButton' 
     }, 
     { 
      xtype: 'component', 
      flex: 1, 
      html: 'Sample component inside dataitem' 
     } 
    ] 
}, 

updateRecord: function(record) { 
    // Provide an implementation to update this container's child items 
    var me = this; 
    me.down('button').setText(record.get('name')); 
} 

}); 

這裏是我的商店: -

Ext.define('MyListItem.store.MyDirectStore', { 
extend: 'Ext.data.Store', 

requires: [ 
    'MyListItem.model.MyModel' 
], 

config: { 
    data: [ 
     { 
      name: 'Adam', 
      age: '28' 
     }, 
     { 
      name: 'Eve', 
      age: '27' 
     } 
    ], 
    model: 'MyListItem.model.MyModel', 
    storeId: 'MyDirectStore' 
} 
}); 

回答

1

我猜你的問題是,你不能檢索處理函數記錄就像你與this.getRecord()

做你可能太更新隨着年齡的按鈕,然後檢索它顯示警報,事端摹狀:

{ 
    xtype: 'button', 
    handler: function(button, e) { 
     console.log("buttonTapped"); 
     Ext.Msg.alert(
      button.getText(), // the title of the alert 
      "The age of this person is: " + button.getAge(); // the message of the alert 
     ); 
    }, 
    text: 'MyButton', 
    age: null 
}, 

和:

updateRecord: function(record) { 
    // Provide an implementation to update this container's child items 
    var button = this.down('button'); 
    button.setText(record.get('name')); 
    button.setAge(record.get('age')); 
} 

更妙的是這將是存儲信息,或者在更合適的地方來記錄的參考,像ListItem本身可能?但是,這應該使它工作。

+0

謝謝阿努比斯。這幫助我 – Kapil

+0

@Anubis,你可以看看我的sencha觸摸問題描述[這裏](http://stackoverflow.com/questions/22457136/sencha-touch-with-phonegap-using-sencha-cmd-and -phonegap-build-causes-error)?會很感激。 – codin

相關問題