【问题标题】:ST2 ListItem setHtml can't get the value of the sub-nodeST2 ListItem setHtml 获取不到子节点的值
【发布时间】:2013-02-04 13:44:27
【问题描述】:

我有两个模型“状态”属于:“用户”,我正在学习名为 touchtweets 的 sencha touch 2 示例。 这是我的 json 文件

{
"statuses" : [{
    "text" : "test",
    "user" : {
        "name" : foo,
              }
             }]
}

官方文档说'当记录更新时,获取文本配置,然后 使用记录的“文本”字段调用setText。但我正在尝试 setHtml:'user.name' 它没有工作,我无法理解。 这是我的视图代码,

Ext.define('Demo.view.StatusesListItem', {
extend : 'Ext.dataview.component.ListItem',
xtype : 'statuseslistitem',
requires : ['Demo.view.StatusesListItemText', 'Ext.Img'],

config : {
    dataMap : {
        getText : {
            setHtml : 'text',        //work well
        },
        getUserName : {
            setHtml : 'user.name',   //didn't work
        }
    },
    userName : {
        cls : 'username'
    },
    text : {
        cls : 'text'
    },
    layout : {
        type : 'vbox'
    }
},
applyUserName : function(config) {
    console.log(Ext.factory(config, Ext.Component, this.getUserName()))
    return Ext.factory(config, Ext.Component, this.getUserName());
},
applyText : function(config) {
    return Ext.factory(config, Sin.view.StatusesListItemText, this.getText());
},
updateTpl : Ext.emptyFn,

});  

Ext.define('Demo.view.StatusesListItemText', {
extend : 'Ext.Component',

applyHtml : function(html) {
    html = html.replace(/(http:\/\/[^\s]*)/g, "<a class=\"link\"       target=\"_blank\" href=\"$1\">$1</a>");
    return html;
}
});

setHtml 获取不到子节点使用的值

有人可以帮助我吗?谢谢你的时间

【问题讨论】:

    标签: sencha-touch-2 dataview listitem


    【解决方案1】:

    很遗憾,这是不可能的。

    解决此问题的方法是将getUserName 的值设置为user,然后更改applyUserName 方法以访问name 属性。

    applyUserName : function(config) {
        var name = config.name;
    
        return Ext.factory(name, Ext.Component, this.getUserName());
    }
    

    【讨论】:

    • Thx ,但我不明白,我已经更改了我的代码 dataMap : { getUserName : { setHtml : 'user', }, } 和 applyUserName 函数,但在 console.log 中的 config.name返回未定义,你能帮我吗
    猜你喜欢
    • 2013-08-10
    • 1970-01-01
    • 1970-01-01
    • 2012-09-17
    • 2016-10-09
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    相关资源
    最近更新 更多