gpt4 book ai didi

javascript - 如何在 Sencha touch 2.1 中创建复杂的数据项?

转载 作者:数据小太阳 更新时间:2023-10-29 06:12:26 24 4
gpt4 key购买 nike

我想在如下所示的列表中创建数据项: Required layout

但我无法渲染具有 3 个组件的中间 vbox 部分。我正在关注这个例子:http://www.sencha.com/blog/dive-into-dataview-with-sencha-touch-2-beta-2/

这就是我定义数据项的方式:

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

我称之为details的中间部分定义为自定义 View ,vbox布局定义如下:

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; 不工作。

最佳答案

我还试图实现一个复杂的数据项布局。我在 hbox 项中使用 vbox 面板并且能够实现它。

检查一下 https://github.com/tomalex0/senchatouch-complex-dataitem

演示 http://tomalex0.github.io/senchatouch-complex-dataitem/

试试看,如果它适合你,请告诉我。

关于javascript - 如何在 Sencha touch 2.1 中创建复杂的数据项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15294371/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com