2013-03-08 12 views
5

私はこのようになります一覧にデータ項目を作成したい: Required layoutSencha touch 2.1で複雑なデータ項目を作成する方法は?

が、私は3つの要素を有する中間vboxセクションをレンダリングすることができません。私はこの例を以下の午前 :

Ext.define('MyTabApp.view.CartListItem', { 
    extend : 'Ext.dataview.component.DataItem', 
    alias : 'widget.cartlistitem', 
    requires: [ 
       'Ext.Img' 
    ], 
    config : { 
     cls: 'cart-list-item', 
     layout: { 
      type: 'hbox', 
      align: 'center' 
     }, 
     image: true, 
     details: { 
      cls: 'x-details', 
      flex: 3, 
     }, 
     pricing: { 
      cls: 'x-pricing', 
      flex: 1 
     }, 
     removeButton: { 
      iconCls  : 'delete', 
      iconMask : true, 
      ui   : 'astonvilla', 
      style  : 'margin-left: 5px; margin-top:10px; padding:5px;' 
     }, 
     moveButton: { 
      iconCls  : 'reply', 
      iconMask : true, 
      ui   : 'astonvilla', 
      style  : 'margin-left: 5px; margin-top:10px; padding:5px;' 
     }, 
     editButton: { 
      iconCls  : 'compose', 
      iconMask : true, 
      ui   : 'astonvilla', 
      style  : 'margin-left: 5px; margin-top:10px; padding:5px;' 
     }, 
     dataMap: { 
      getImage: { 
       setSrc   : 'itemImage' 
      }, 

      getDetails: { 
       setItemTitle : 'title', 
       setQuantity  : 'quantity' 
      }, 

      getPricing: { 
       setHtml   : 'totalPrice' 
      }, 
     }, 
    }, 
    applyImage: function(config) { 
     return Ext.factory(config, Ext.Img, this.getImage()); 
    }, 

    updateImage: function(newImage, oldImage) { 
     if (newImage) { 
      this.add(newImage); 
     } 

     if (oldImage) { 
      this.remove(oldImage); 
     } 
    }, 

    applyDetails: function(config) { 
     console.log("applyDetails"); 
     var details = Ext.factory(config, MyTabApp.view.CartListItemDetails, this.getDetails()); 
     console.log("applyDetails done"); 
     console.log(details); 
     return details; 
    }, 

    updateDetails: function(newDetails, oldDetails) { 
     console.log("updateDetails"); 
     if (newDetails) { 
      this.add(newDetails); 
     } 

     if (oldDetails) { 
      this.remove(oldDetails); 
     } 
    }, 

    applyPricing: function(config) { 
     return Ext.factory(config, Ext.Component, this.getPricing()); 
    }, 

    updatePricing: function(newPricing, oldPricing) { 
     if (newPricing) { 
      this.add(newPricing); 
     } 

     if (oldPricing) { 
      this.remove(oldPricing); 
     } 
    }, 

    applyRemoveButton: function(config) { 
     return Ext.factory(config, Ext.Button, this.getRemoveButton()); 
    }, 

    updateRemoveButton: function(newRemoveButton, oldRemoveButton) { 
     if (oldRemoveButton) { 
      this.remove(oldRemoveButton); 
     } 

     if (newRemoveButton) { 
      // add an event listeners for the `tap` event onto the new button, and tell it to call the onNameButtonTap method 
      // when it happens 
      newRemoveButton.on('tap', this.onRemoveButtonTap, this); 

      this.add(newRemoveButton); 
     } 
    }, 

    onRemoveButtonTap: function(button, e) { 
     var record = this.getRecord(); 

     Ext.Msg.alert(
      record.get('title'), // the title of the alert 
      "Id of this item is: " + record.get('itemId') // the message of the alert 
     ); 
    }, 

    applyEditButton: function(config) { 
     return Ext.factory(config, Ext.Button, this.getEditButton()); 
    }, 

    updateEditButton: function(newEditButton, oldEditButton) { 
     if (oldEditButton) { 
      this.remove(oldEditButton); 
     } 

     if (newEditButton) { 
      // add an event listeners for the `tap` event onto the new button, and tell it to call the onNameButtonTap method 
      // when it happens 
      newEditButton.on('tap', this.onEditButtonTap, this); 

      this.add(newEditButton); 
     } 
    }, 

    onEditButtonTap: function(button, e) { 
     var record = this.getRecord(); 

     Ext.Msg.alert(
      record.get('title'), // the title of the alert 
      "Id of this item is: " + record.get('itemId') // the message of the alert 
     ); 
    }, 

    applyMoveButton: function(config) { 
     return Ext.factory(config, Ext.Button, this.getMoveButton()); 
    }, 

    updateMoveButton: function(newMoveButton, oldMoveButton) { 
     if (oldMoveButton) { 
      this.remove(oldMoveButton); 
     } 

     if (newMoveButton) { 
      // add an event listeners for the `tap` event onto the new button, and tell it to call the onNameButtonTap method 
      // when it happens 
      newMoveButton.on('tap', this.onMoveButtonTap, this); 

      this.add(newMoveButton); 
     } 
    }, 

    onMoveButtonTap: function(button, e) { 
     var record = this.getRecord(); 

     Ext.Msg.alert(
      record.get('title'), // the title of the alert 
      "Id of this item is: " + record.get('itemId') // the message of the alert 
     ); 
    } 
}); 

そしてvboxレイアウトとカスタムビューは、次のように定義されているように私はdetailsを呼び出しています中央のセクションが定義されている:http://www.sencha.com/blog/dive-into-dataview-with-sencha-touch-2-beta-2/

は、これは私が私のデータ項目を定義しています方法です:

Ext.define('MyTabApp.view.CartListItemDetails', { 
    extend : 'Ext.Component', 
    alias : 'widget.cartlistitemdetails', 
    config : { 
     cls  : 'x-details', 
     flex : 3, 
     layout : 'vbox', 
     titleCell: null, 
     qtyCell: null, 
     items : [{ 
      xtype : 'panel', 
      flex : 1, 
      itemId : 'titleCell', 
      html : 'blahblah' 
     }, 
     { 
      xtype : 'component', 
      flex : 1, 
      itemId : 'qtyCell', 
      html : 'blahblah' 
     }], 
    }, 
    setItemTitle : function(title){ 
//  this.down('#titleCell').setHtml(title); 
     console.log(this.getItems()); 
     this.getItems()[0].html = title; 
    }, 
    setQuantity : function(qty){ 
//  this.down('#qtyCell').setHtml(qty); 
     console.log(this.getItems()); 
     this.getItems()[0].html = qty; 
    } 
}); 

これは&水平に整列ボタンを価格設定、画像とリスト項目をレンダリングしています。カスタムコンポーネントである中間セクションはレンダリングされません。私は要素を検査した場合には、HTMLが生成される方法です。

<div class="x-details x-layout-box-item x-flexed x-stretched" id="ext-cartlistitemdetails-1" style="-webkit-box-flex: 3;"></div> 

あなたはこのdivの内側には何もありません見ることができ、これは、それがどのようにレンダリングされるかであるよう:

Actual list items

を私が近いだと思われますsetItemTitleメソッドが呼び出されているのにまだthis.down('#titleCell').setHtml(title)またはthis.getItems()[0].html = title;が機能していないためです。

+1

すべてではわかりませんが、なぜ「CartListItemDetails」には2つの項目しかありませんか?また、なぜ 'titleCell'が' panel'で、 'qtyCell'が' component'ですか?しかし実際には、 'CartListItemDetails'をHTMLコンテンツのシンプルな' panel'にするだけでCSSでスタイルを作るのはなぜですか? – jakerella

+0

私はHTMLテンプレートとCSSマジックでもやっています。次に、リストにはアイテムタップリスナーのみがあります。 itemtapリスナーによって呼び出される関数では、タップ・イベントのターゲットを把握することができ、したがって他の関数をトリガーすることができます。 –

+0

@ジャケレラ実際には欲求不満のために追加/削除/変更されたものが多いため、3つではなく2つのアイテムがあり、またパネルとコンテナがあります。 – ThinkFloyd

答えて

6

私はまた、複雑なデータ項目レイアウトを実装しようとしていました。私は、hboxアイテム内にvboxパネルを使用しており、それを実装することができます。

それをチェックアウト https://github.com/tomalex0/senchatouch-complex-dataitem

デモ http://tomalex0.github.io/senchatouch-complex-dataitem/

それを試してみて、それはあなたのために働くなら、私に知らせてください。

関連する問題