2014-02-23 9 views
1

Ext.dataview.component.ListItem을 사용하여 sencha touch 2.3 (sencha 아키텍트 사용)에 목록을 작성하려고합니다. updateRecord 메서드를 사용하여 상점에서 값을 가져올 수 있었지만 주 구성 요소로 다시 전달할 수는 없습니다.건축가를 사용하여 Sencha 2.3의 DataView 구성 요소 목록 항목

이 내가 달성하기 위해 노력하고 무엇 : -

내가 그 텍스트 저장소에서 동적으로 표시되며 사용자가 클릭 한 경우는 나이가 경고를 표시해야합니다 버튼의 목록을 만들려고합니다. 나는 그 안에 이름과 나이가있는 가게가있다. 클래스 다음

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')); 
} 

}); 

을 dataView 내가 이름을 얻을 수 있어요하지만 난 여기 드리려고 과 관련하여 도움이 필요 경고 setup.I을 얻을 수 없습니다 나는 것은 내 가게입니다 : -

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 
}, 

그리고 : 같은 g

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