如何解决如何从Sencha Touch中的数据存储中显示标签中的数据
| 我想显示我从数据存储中收到的数据。我尝试过的一种方法是,使文本字段处于禁用状态,然后使用存储数据设置其值。 但是我不认为这是正确的解决方案,因此我尝试使用label代替,但是我没有得到如何完成的方法。你们能指出我正确的做法吗?任何帮助表示赞赏。 谢谢, Mehul Makwana。解决方法
我最近尝试通过创建\'label \'表单组件来解决此问题。我在Sencha / PhoneGap上写的博客文章中对此发表了看法。这是代码:
Ext.form.LabelField = function(config){
Ext.form.LabelField.superclass.constructor.call(this,config);
};
Ext.extend(Ext.form.LabelField,Ext.form.Field,{
isField: true,value: \'\',renderSelectors: {fieldEl: \'.x-form-labelfield\'},renderTpl: [
\'<tpl if=\"label\">\',\'<div class=\"x-form-label\"><span>{label}</span></div>\',\'</tpl>\',\'<div class=\"x-form-label x-form-labelfield\" style=\"width:70%; text-align:right\"><span>{value}</span></div>\',],setValue:function(val) {
this.value = val;
if(this.rendered){
this.fieldEl.update(\'<span>\' + val + \'</span>\');
}
return this;
},});
Ext.reg(\'labelfield\',Ext.form.LabelField);
让我知道这是否有用。
,这篇文章有些陈旧,但我正在针对同一主题进行研究,最终使用了不同的方法。
我正在使用Sencha Touch v2.0。我创建标签并将其放置在form.Panel内部,就像通常那样。然后,我在设计器中将标签tpl配置为包括模型字段。当将值应用于formpanel时,我还要在标签tpl上调用apply()方法。下面的工作示例对此进行了说明。
app.js:
Ext.Loader.setConfig({
enabled: true
});
Ext.application({
views: [
\'MyFormPanel\'
],name: \'MyApp\',launch: function() {
Ext.create(\'MyApp.view.MyFormPanel\',{fullscreen: true});
}
});
view.MyFormPanel.js
Ext.define(\'MyApp.view.MyFormPanel\',{
extend: \'Ext.form.Panel\',alias: \'widget.myformpanel\',config: {
items: [
{
xtype: \'label\',itemId: \'myLabel\',tpl: [
\'Hello,{firstName} {lastName},please change your email below:\',\'\'
]
},{
xtype: \'textfield\',label: \'Email:\'
}
],listeners: [
{
fn: \'onFormpanelInitialize\',event: \'initialize\'
}
]
},onFormpanelInitialize: function(component,options) {
var person = Ext.decode(\"{firstName: \'John\',lastName: \'Dow\',email: \'jd@somewhere.com\'}\");
// apply value to the form
this.setValues(person);
// get the updated text for the label
var label = this.down(\'#myLabel\');
var html = label.getTpl().apply(person);
label.setHtml(html);
}
});
因此,想法是将标签模板保存在label.tpl字段中,然后使用Template的apply()方法获取运行时标签值,然后为其设置标签文本。
,谢谢mstagrooves。那正是我想要的。我建议删除x-form-label类并使用以下样式:
.x-form-labelfield {
-webkit-box-flex: 1;
box-flex: 1;
width: 100%;
position: relative;
-webkit-border-radius: 0;
border-radius: 0;
padding: .4em;
border: 0;
min-height: 2.5em;
display: block;
background: white none;
-webkit-appearance: none;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。