2012-03-16 2 views
1

중첩 된 목록에 대해 다음 코드를 가지고 있으며 "장바구니에 추가 버튼"에 onclick() 이벤트를 작성하려고합니다. 이 버튼은 html 요소입니다. 그래서 나는 어떻게 이벤트를 쓴다 ???hench 요소에 대한 Sencha 터치 이벤트 핸들러

기본적으로 버튼 클릭시 데이터베이스에 가격과 수량을 추가하고 싶습니다.

코드가 이렇게됩니다.

Ext.setup({ 
tabletStartupScreen: 'tablet_startup.png', 
phoneStartupScreen: 'phone_startup.png', 
icon: 'icons/logo4_1.png', 
glossOnIcon: true, 

title:'Item List', 
fullscree:true, 
onReady: function() { 

var data = { 
title:'Item List', 
    text: 'Groceries', 
    items: [{ 
     text: 'Beverages', 
     cont:'>', 
     imgURL:'<div align="center"><img src="icons\\Beverages.jpg" width="60" heigh="60"/></div>', 
     items: [{ 
      text: 'Water 1Ltr', 
      price:'18rs/btl', 
      imgURL:'<img src="images\\beverage\\water.jpg" width="60" heigh="60"/>', 
      element:'<div align="right" width="20"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
      leaf:true, 
      }, 
      { 
      text:'Coffee', 
      price:'45rs/pack', 
      imgURL:'<img src="images\\beverage\\bru.jpg" width="60" heigh="60"/>', 
      element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
      leaf: true 
     }, { 
      text: 'Espresso', 
      price:'50rs/pack', 
      imgURL:'<img src="images\\beverage\\espresson.jpg" width="60" heigh="60"/>', 
      element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
      leaf: true 
     }, { 
      text: 'Redbull', 
      price:'50rs/Can', 
      imgURL:'<img src="images\\beverage\\redbull.jpg" width="60" heigh="60"/>', 
      element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
      leaf: true 
     }, { 
      text: 'Coke', 
      price:'35rs/Can', 
      imgURL:'<img src="images\\beverage\\coke.jpg" width="60" heigh="60"/>', 
      element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
      leaf: true 
     }, { 
      text: 'Diet Coke', 
      price:'40rs/Can', 
      imgURL:'<img src="images\\beverage\\dietcoke.jpg" width="60" heigh="60"/>', 
      element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
      leaf: true 
     }] 
    },{ 
    text: 'Fruits', 
    cont:'>', 
    imgURL:'<div align="center"><img src="icons\\fv.jpg" width="60" heigh="60"/></div>', 
    items: [{ 
     text: 'Bananas', 
     price:'25rs/Kg', 
     imgURL:'<img src="images\\fv\\banana.jpg" width="60" heigh="60"/>', 
     element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
     leaf: true 
    }, 
    { 
     text: 'Watermelon', 
     price:'15rs/Kg', 
     imgURL:'<img src="images\\fv\\watermelon.jpg" width="60" heigh="60"/>', 
     element:'<div align="right"> Qty:<input type="text" width="20"/><button>Add to Cart</button></div>', 
     leaf: true 
    } 
    , 
    { 
     text: 'Grapes', 
     cont:'>', 
     imgURL:'<div align="center"><img src="images\\fv\\grapes.jpg" width="60" heigh="60"/></div>', 
     items: [ 
     {text:'Black Grapes', 
     element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
     price:'25rs/Kg', 
     imgURL:'<img src="images\\fv\\blackgrapes.jpg" width="60" heigh="60"/>', 
     leaf: true 
     }, 
     { 
     text:'Green Grapes', 
     price:'20rs/Kg', 
     element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
     imgURL:'<img src="images\\fv\\greengrapes.jpg" width="60" heigh="60"/>', 
     leaf:true 
     }] 
    }, 
    { 
     text: 'Pear', 
     price:'125rs/Kg', 

     element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
     imgURL:'<img src="images\\fv\\pear.jpg" width="60" heigh="60"/>', 
     items:[{xtype:'button',ui:'action'}], 
     leaf: true 
    } 
    ,{ 
     text: 'Apple', 
     price:'105rs/Kg', 
     element:'<div align="right"> Qty:<input type="text"/><button onclick="function show(){alert("hello");}">Add to Cart</button></div>', 
     imgURL:'<img src="images\\fv\\apple.jpg" width="60" heigh="60"/>', 
     leaf: true 
    }] 
    }, 
    { 
     text: 'Bakery', 
     cont:'>', 
     imgURL:'<div align="center"><img src="icons\\bread_Bakery.jpg" width="60" heigh="60"/></div>', 
     items: [{ 
      text: 'Bread', 
      imgURL:'<div align="center"><img src="images\\bread\\bread.jpg" width="60" heigh="60"/></div>', 
      cont:'>', 
      items: [{ 
      text: 'White Bread', 
      price:'18rs/Pound', 
      element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
      imgURL:'<img src="images\\bread\\white.jpg" width="60" heigh="60"/>', 
      leaf: true, 
      }, 
      { 
      text: 'Brown Bread', 
      price:'25rs/Pound', 
      element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
      imgURL:'<img src="images\\bread\\brown.jpg" width="60" heigh="60"/>', 
      leaf: true, 
      }, 
      ] 
    },{ 
     text: 'Stuffed Bread Rolls', 
     price:'15rs/Piece', 
     element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
     imgURL:'<img src="images\\bread\\rolls.jpg" width="60" heigh="60"/>', 
     leaf: true 
    },{ 
     text: 'Cup Cakes', 
     price:'10rs/Piece', 
     element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
     imgURL:'<img src="images\\bread\\cupcake.jpg" width="60" heigh="60"/>', 
     leaf: true 
    }] 
},{ 
    text: 'Personal Care', 
    cont:'>', 
    imgURL:'<div align="center"><img src="icons\\Personal_Care.jpg" width="60" heigh="60"/></div>', 
    items: [ 
    { 
     text: 'Shampoo 500ml', 
     cont:'>', 
     imgURL:'<div align="center"><img src="images\\pc\\shampoo.jpg" width="60" heigh="60"/></div>', 
     items: [ 
    { 
     text: 'Dove', 
     price:'59rs/Btl', 
     element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
     imgURL:'<img src="images\\pc\\shampoo.jpg" width="60" heigh="60"/>', 
     leaf:true, 
    }, 
    { 
     text: 'Sunsilk', 
     price:'62rs/Btl', 
     element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
     imgURL:'<img src="images\\pc\\sunsilk.jpg" width="60" heigh="60"/>', 
     leaf:true, 
    }, 
    { 
     text: 'Garnier', 
     price:'70rs/Btl', 
     element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
     imgURL:'<img src="images\\pc\\garnier.jpg" width="60" heigh="60"/>', 
     leaf:true, 
    }, 
    ] 
    }, 
    { 
     text: 'Soaps 50gms', 
     cont:'>', 
     imgURL:'<div align="center"><img src="images\\pc\\soap.jpg" width="60" heigh="60"/> </div>', 
     items: [ 
    { 
     text: 'Dove', 
     price:'25rs/Piece', 
     element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
     imgURL:'<img src="images\\pc\\dove.jpg" width="60" heigh="60"/>', 
     leaf:true, 
    }, 
    { 
     text: 'Pears', 
     price:'28rs/Piece', 
     element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
     imgURL:'<img src="images\\pc\\pears.jpg" width="60" heigh="60"/>', 
     leaf:true, 
    }, 
    { 
     text: 'Lux', 
     price:'20rs/Piece', 
     element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
     imgURL:'<img src="images\\pc\\lux.jif" width="60" heigh="60"/>', 
     leaf:true, 
    }, 
    ] 
    }, 
    { 
     text: 'Hair Oil 500ml', 
     cont:'>', 
     imgURL:'<div align="center"><img src="images\\pc\\hairoil.jpg" width="60" heigh="60"/></div>', 
     items: [ 
    { 
     text: 'Vatika', 
     price:'25rs/Btl', 
     element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
     imgURL:'<img src="images\\pc\\vatika.jpg" width="60" heigh="60"/>', 
     leaf:true, 
    }, 
    { 
     text: 'Almond Oil', 
     price:'50rs/Btl', 
     element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
     imgURL:'<img src="images\\pc\\almond.jpg" width="60" heigh="60"/>', 
     leaf:true, 
    }, 
    { 
     text: 'Parachute Jasmine oil', 
     price:'35rs/Btl', 
     element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
     imgURL:'<img src="images\\pc\\hairoil.jpg" width="60" heigh="60"/>', 
     leaf:true, 
    }, 
    ] 
    }, 
    { 
     text: 'Body Lotions 500ml', 
     cont:'>', 
     imgURL:'<div align="center"><img src="images\\pc\\lotion.jpg" width="60" heigh="60"/></div>', 
     items: [ 
    { 
     text: 'Vaseline', 
     price:'40rs/Btl', 
     element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
     imgURL:'<img src="images\\pc\\vas.jpg" width="60" heigh="60"/>', 
     leaf:true, 
    }, 
    { 
     text: 'Ponds', 
     price:'35rs/Btl', 
     element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
     imgURL:'<img src="images\\pc\\ponds.jpg" width="60" heigh="60"/>', 
     leaf:true, 
    }, 
    { 
     text: 'Nivea', 
     price:'70rs/Btl', 
     element:'<div align="right"> Qty:<input type="text"/><button>Add to Cart</button></div>', 
     imgURL:'<img src="images\\pc\\nivea.jpg" width="60" heigh="60"/>', 
     leaf:true, 
    }, 
    ] 
    }, 

    ] 
}] 

}};

Ext.regModel('ListItem', { 
    fields: ['text','price','imgURL','element','cont'], 
    //fields: [{name: 'text', type: 'string'},{name: 'imageURL', type: 'string'}], 

}); 

var store = new Ext.data.TreeStore({ 
    model: 'ListItem', 
    root: data, 
    proxy: { 
     type: 'ajax', 
     reader: { 
      type: 'tree', 
      root: 'items' 
     } 
    } 
}); 

var leftNav = new Ext.NestedList({ 
fullscreen:true, 

    dock: 'center', 
    useTitleAsBackText: true, 
    title: 'Item List', 
    icon: 'icons/logo4_1.png', 
    width: '350', 
    html:'<div align="right"><img src="icons/cart.jpg" width="40" height="40"/></div>', 
    store: store, 
    dockedItems:[ 
    { 
    xtype:'panel', 
    dock:'bottom', 
    items: 
    [{ 
    xtype:'button', 
    ui:'confirm', 
    text:'Proceed to Pay', 
    handler:function(btn,evt) 
    { 
    window.location="cart.html"; 
    } 
    }], 
    }], 
    getItemTextTpl: function(node) 
    { 
    return ' {text} <div align="right">{items}</div><div align="right">{element}</div><div align="right">{cont}</div> {imgURL}<div align="left">{price}</div>'; 
    } , 
    listeners: { 
    afterrender: function() { 
    var port=new Ext.Button({ 
      ui: 'plain', 
      height:'50', 
      width:'50', 
      html:'<div align="right"><img src="icons/cart.jpg" width="50" height="50"/></div>',scope: this, 
      handler: function(btn,evt) 
      { 
      window.location="cart.html"; 
      } 
     }); 
     this.toolbar.add(port); 
    } 
}, 
}); 

new Ext.Panel({ 
    fullscreen: true, 
     html:'<div align="right"><img src="icons/logo4_1.png" width="100" height="40"/></div>', 
    layout: { 
     type: 'vbox', 
     align: 'stretch' 

    }, 
    defaults: { 
    xtype:'button', 
    ui:'action', 
     flex: 1 
    }, 
    dockedItems:[leftNav] 
}); 

모든 답변에 감사드립니다 :)

+0

Sencha가 이러한 이벤트를 삭제하기 때문에 OnClick 이벤트가 발생하지 않을 수 있습니다. 이것은 onclick 함수가 작동하지 않을 것임을 의미합니다 .. 아마도 Ext Components 만 사용해야합니다. – Rob

+0

그리고 어떻게해야합니까 .. 그 일은 단지 3 일간의 sencha만으로도 외국에서 찾을 수 있습니다. ( – Apoorva

+1

Sencha는 JSON 구성에서 HTML 코드를 만듭니다. 그래서 다음과 같은 결과가 나옵니다. Ext.create ('Ext.button', {text : 'test'})); test – Rob

답변

1

정말 열심히, 당신은 HTML 코드에서 너무 많이 생각하고 있습니다. Sencha는 객체와 유사한 JSON 구성에서 HTML 코드를 생성합니다. 따라서 다음과 같은 Sencha 구성은 Ext.create('Ext.button', { text: 'test' });과 같이 나타납니다. <input type='button'>test</input>

-2

당신은이

onClick="javascript:nameTaps">{Name} 

을 추가하여 HTML에서 할 및 핸들러에 대한 nameTaps 기능을 정의 할 수 있습니다 자바 스크립트를 사용하는 경우.

+0

난 ... – Apoorva

+0

은 onClick 이벤트를 사용해서는 안되며, sencha는 다른 브라우저에서 브라우저 이벤트를 정상화하여 사용해야합니다. 그것은 –

+0

iam 내 div 태그에서 동일한 것을 사용하고 완벽하게 작동합니다. 그리드에서 onclick 이벤트를 사용하여 드릴 다운 차트를 표시합니다. – Nag