如何在 Sencha Touch 中的数据存储中显示标签中的数据

发布于 2024-11-10 00:01:16 字数 145 浏览 3 评论 0原文

我想显示从数据存储接收的数据。我尝试过的一种方法是采用一个文本字段将其禁用,然后使用存储数据设置其值。 但我不认为这是正确的解决方案,所以我尝试使用标签来代替,但我不知道如何做到这一点。你们能指出我正确的做法吗?任何帮助表示赞赏。

谢谢, 梅胡尔·马克瓦纳。

I want to display data that i receive from a data store. One way that i have tried, is to take a text field make it disabled and then set its value with store data.
But i don't think it is the correct solution so i am trying to use label instead and I am not getting how it can be done. Can you guys can point me to correct way of doing it.? Any help appreciated .

Thanks,
Mehul Makwana.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

墨落成白 2024-11-17 00:01:16

这篇文章有点旧,但我正在研究同一主题并最终使用了不同的方法。

我正在使用 Sencha Touch v2.0。我创建标签并将其放置在 form.Panel 中,就像通常所做的那样。然后,我在设计器中配置了标签 tpl 以包含模型字段。将值应用到表单面板时,我还会调用标签 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: '[email protected]'}");
    // 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() 方法获取运行时标签值,然后将标签文本设置给它。

This post is a little old but I was research the for same topic and ended up using a different approach.

I'm using Sencha Touch v2.0. I create the label and place it inside the form.Panel as one would normally do. I then configured the label tpl in designer to include the model fields. When applying the values to the formpanel, I also invoke the apply() method on the label tpl. The following working sample illustrate it.

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: '[email protected]'}");
    // 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);

    }

});

So the idea is save the label template in the label.tpl field, then get the runtime label value using apply() method of Template, then set the label text to it.

葬シ愛 2024-11-17 00:01:16

我最近尝试通过创建“标签”表单组件来解决这个问题。我在 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);

让我知道这是否有效。

I recently tried to solve this problem by creating a 'label' form component. I posted about it in a blog article I wrote on Sencha/PhoneGap. Here is the code:

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

Let me know if this does the trick.

冷弦 2024-11-17 00:01:16

谢谢你。这正是我所寻找的。我建议删除 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;
}

Thank you mistagrooves. That was exactly what I was looking for. I reccomand removing x-form-label class and using these styles:

.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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文