1

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

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

   });

}

下面的代码是视图,我从控制器函数(上图)传递值。Hard coded text下面的代码演示了该视图中的硬编码数据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.)从视图中,我如何添加按钮?并且当用户单击该按钮时,我如何获取该result.age字段并执行 if 条件来检查年龄是否低于 10 岁?

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

更新2

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

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

1 回答 1

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},然后在上面的代码片段中,您可以看到我在 config 中使用它们就像在(with config)tpl中正常使用一样。那么我该怎么做呢?Ext.Liststore

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

其次,tpl在你看来定义,我相信你可以从上面的例子中弄清楚。

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

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

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

于 2012-05-14T15:51:46.837 回答