这里是我用来实现Xtemplate的代码,但它没有显示任何值,即使JSON响应成功
XTemplate
var tab = Ext.create('Ext.Panel', {
id: 'itemList',
flex:1,
width: '100%',
items: [{
id: 'itemList',
width: '100%',
tpl: new Ext.XTemplate(
'<div style="margin:0px;" ><table style="margin:0px;padding:0px;height:40px;" width="100%" ><tr><td style="padding:2px 5px;width:90%;"><img src="data:image/jpeg;base64,{itemImage}"/>{itemImage}</td><td style="padding:2px 10px;width:10%;"><img src="resources/img/arrow.png" onclick="invitefriends{\'{userId}\',this)"/></td></tr></table></div>', {
getDifference: function (t365, tytd) {
return parseFloat(t365 - tytd).toFixed(2);
},
getCvsWidth: function () {
//return screen.width - 210;
if ((window.innerWidth - 210) < 350) {
return 350;
} else {
return window.innerWidth - 210;
}
}
})
}]
}
JSON方法
function viewgiftlist() {
Ext.Viewport.mask({ xtype: 'loadmask' });
Ext.Ajax.request({
url: App.gvars.apiurl + 'ShowItems/userID='+App.gvars.userid,
method: "GET",
useDefaultXhrHeader: false,
withCredentials: true,
success: function (response) {
var respObjs = Ext.JSON.decode(response.responseText);
Ext.Viewport.mask({ xtype: 'loadmask' });
if(respObjs.showItems[0].response=="Success")
{
IsLoggedIn1 = "true";
Ext.getCmp('itemList').setData(respObjs.showItems);
Ext.Viewport.unmask();
}
if(respObjs.showItems[0].response=="failed")
{
Ext.Viewport.unmask();
Ext.Msg.alert("Alert!","No items found! Please add item.");
}
},
failure: function (response) {
Ext.Viewport.unmask();
var respObj = Ext.JSON.decode(response.responseText);
Ext.Msg.alert("Error",response.responseText);
}
});
}
我的XTemplate创建有什么问题请帮助我
答案 0 :(得分:0)
你应该尝试下面这样的事情。
Ext.create('Ext.List', {
width: 320,
height: 290,
id : 'itemList',
itemTpl: ['<div style="margin:0px;background:#fff;" >'+
'<table style="margin:0px;padding:0px;height:40px;" width="100%" >'+
'<tr><td style="padding:2px 5px;width:90%;"><span><img src=""/>'+
'</span><span>{itemName}<br>{itemDesc}</span></td>'+
'<td style="padding:2px 10px;width:10%;">'+
'<img src="resources/img/arrow.png" />'+
'</td></tr></table></div>'].join(),
listeners : {
itemtap: function (list, index, item, record, senchaEvent) {
if (senchaEvent.event.target.nodeName == 'IMG') {
var data = record.getData();
var itemId = data.itemId;
var itemPurchased = data.itemPurchased;
// Call viewgiftdetails method and pass itemId and itemPurchased
}
}
}
});