在视图上显示文本

时间:2012-05-14 15:49:09

标签: sencha-touch extjs sencha-touch-2

以下代码是我的控制器功能的一部分;

success: function (response) {

                            var text = response.responseText;

                            var result = Ext.decode(response.responseText);

                            var indexPanel = Ext.create('app.view.PersonDetails');

                            Ext.getCmp('mainView').push({

   xtype:'person',

   data: result

   });

}

下面的代码是视图,我从Controller函数传递值(上图)。 下面的代码演示了该视图中的硬编码数据(Hard coded text),但我想要做的是显示我从Controller函数(上面)传递的data: result以显示在下面视图。我怎么能这样做?

Ext.define('app.view.UserInformation',{

           extend:'Ext.Panel',

           xtype:'person',

           config: {
                title:'Person details',       
    html:['Hard coded text'].join("")
           }

});

更新

result包含多个值,例如;

result.name, result.age. result.gender

我将result传递给另一个视图。

1。)从View中,我该如何添加一个按钮?如果用户点击该按钮,我如何获取result.age字段并执行if条件以检查年龄是否低于10?

2。)想象一下,如果有一个名为result.imageurl的字段,我怎样才能在另一个视图上显示图像(在一个框架中)?

UPDATE2

Ext.getCmp('mainpanel').push({

 title: 'Hello ' ,
xtype:'person'
});
Ext.getCmp('idOfTheView').setRecord(result.first_name);

1 个答案:

答案 0 :(得分:0)

您的问题仅为Sencha Touch,与PhoneGap无关。 :)

假设您的视图的ID为view_id

然后在你的控制器功能中:

Ext.getCmp('view_id').setHtml(what you want to put into your view)

更新回答:

您的问题包含几个子问题。我担心你所要求的范围太宽,但我会回答最重要的部分。

(来自我自己的申请):

Ext.define('rs.view.ProductInfo', {
    extend: 'Ext.Container',
    xtype: 'ProductInfo',
    id: 'product-info',
    cls: 'product-info',

    config: {
            items: [
                    {
                            xtype: 'panel',
                            styleHtmlContent: true,
                            id: 'product-info-header',
                            tpl: [
                                    '<div class="product-info-header">',
                                            '<img src={image} width="100px" height="100px"/>',
                                            '<h3>{name}</h3>',
                                            '<h4>Price: {price}</h4>',
                                            '<h4>Seller: {sellerUsername}</h4>',
                                    '</div>',
                            ],
                    },
            ],
    }
});

请注意,我使用属性{image},{name},{price},{sellerUsername}定义了一个模型,然后在上面的代码段中,您可以看到我在tpl配置中使用它们,就像在Ext.List中正常使用一样(使用store配置)。那我怎么能这样做呢?

首先,您必须定义描述结果的模型。明显。

其次,在您的视图中定义tpl,我相信您可以从上面的示例中找到它。

最后,使用此(假设您已将从服务器收到的结果写入我在第一步中提到的Model实例中):

Ext.getCmp('your_view_id').setRecord(your_model_instance)

100%工作保修,因为我已经多次使用过这种保修。希望能帮助到你。如果您有任何疑问,请发表评论。