gpt4 book ai didi

javascript - sencha touch 将变量添加到模板/列表/等

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:50:28 25 4
gpt4 key购买 nike

环顾四周,我没有找到 Sencha Touch 的解决方案(虽然我设法让它与 ExtJS 一起工作)所以我求助于你。

Sencha touch 的新手,我学会了如何正确地将 stor 绑定(bind)到 List 组件。

我的问题是我需要处理特定记录,然后再将其呈现为模板。

我的记录坐标是这样的:

2.356095,48.879154,0.000000

我使用 ExtJS 创建了一个函数,将它拆分并呈现一个指向 GMaps 的链接。

我的问题:

我可以像在 extJS (record.data.coordinates) 中访问我的记录吗?

如何添加新变量以在 itemTpl 中使用?

MyAPP = new Ext.Application({
name: 'ListDemo',
launch: function() {

MyAPP.listPanel = new Ext.List({
id: 'indexlist',
store: MyAPP.ListStore,
itemTpl: '<div>{name}<br>{coordinates}</div>'

}); // end of MyAPP.listPanel

function renderMap(value, p, record) {
var split = record.data.coordinates.split(',');
var lat = split[0];
var lon = split[1];
return Ext.String.format(
'<b><a href="http://maps.google.com/maps?q={2}+{1}+({3})" target="_blank">Google Map</a>',
value,
lat,
lon,
record.data.Adresse
);
}
}
});

谢谢你的帮助,

朱利叶斯。

最佳答案

您可以在模板中使用内联 javascript 代码来拆分坐标变量。这是文档中的示例:

var tpl = new Ext.XTemplate(
'<p>Name: {name}</p>',
'<p>Company: {[values.company.toUpperCase() + ", " + values.title]}</p>',
'<p>Kids: ',
'<tpl for="kids">',
'<div class="{[xindex % 2 === 0 ? "even" : "odd"]}">',
'{name}',
'</div>',
'</tpl></p>'
);

注意 values.company.toUpperCase() 是如何处理的。因此,要获取您的变量,您可以执行 values.coordinates

另一种解决方案是使用模板成员函数。这是 sencha 文档中的另一个示例。

var tpl = new Ext.XTemplate(
'<p>Name: {name}</p>',
'<p>Kids: ',
'<tpl for="kids">',
'<tpl if="this.isGirl(name)">',
'<p>Girl: {name} - {age}</p>',
'</tpl>',
// use opposite if statement to simulate 'else' processing:
'<tpl if="this.isGirl(name) == false">',
'<p>Boy: {name} - {age}</p>',
'</tpl>',
'<tpl if="this.isBaby(age)">',
'<p>{name} is a baby!</p>',
'</tpl>',
'</tpl></p>',
{
// XTemplate configuration:
compiled: true,
// member functions:
isGirl: function(name){
return name == 'Sara Grace';
},
isBaby: function(age){
return age < 1;
}
}
);

在此处查看文档 http://docs.sencha.com/touch/1-1/#!/api/Ext.XTemplate如果您需要更多帮助。

在此代码之前定义tpl对象。

 MyAPP.listPanel = new Ext.List({
id: 'indexlist',
store: MyAPP.ListStore,
itemTpl: tpl // use the tpl object like this

});

关于javascript - sencha touch 将变量添加到模板/列表/等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8154597/

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