【问题标题】:split method for text value in AppceleratorAppcelerator中文本值的拆分方法
【发布时间】:2024-01-16 11:21:01
【问题描述】:

我有一个窗口,可以在标签中显示我的推文。

我的推文来自我的 FB 页面状态,如果我放了一张图片或写了超过 140 个字符,那么我会在推文中获得一个指向实际帖子的链接。

我想知道是否有任何方法可以拆分标签文本,以便我可以将链接指向要在 webview 中打开的 url

这是我已经走了多远:

var win = Ti.UI.currentWindow;

win.showNavBar();

        var  desc = Ti.UI.createLabel({
        text: win.data,
        font:{
            fontSize:'20dp',
        fontWeight:'bold'
    },
    height:'300dp',
    left:'5dp',
    top:'10dp',
    color:'#111',
    touchEnabled:true
    });


  win.add(desc);


        desc.addEventListener('click',function(e){
var v = desc.text;

if(v.indexOf('http') != -1){
    // open new window with webview
    var tubeWindow = Ti.UI.createWindow({ 
    modal: true,
    barColor: '#050505',
    backgroundColor: '#050505' 
}); 
    var linkview = Ti.UI.createWebView({
            url:  e.v,
            barColor: '#050505',
            backgroundColor: '#050505'              
        });
        // Create a button to close the modal window
var close_modal = Titanium.UI.createButton({title:'Stäng'});
tubeWindow.rightNavButton = close_modal;

// Handle close_modal event
close_modal.addEventListener('click', function() {
    tubeWindow.close();
});
 tubeWindow.add(linkview);
tubeWindow.open({
     modalTransitionStyle: Ti.UI.iPhone.MODAL_TRANSITION_STYLE_FLIP_HORIZONTAL,
});

}
});
win.open(); 

我被告知我需要拆分 win.data 以获取链接。 (win.data 是推文)

现在我只有:url: e.v,我需要把链接拿出来

关于它如何工作的任何想法?

感谢

//R

【问题讨论】:

  • 我的回答有帮助吗?如果是这样,其他人可能对此感兴趣,请投票/标记最佳答案或添加评论说明有什么问题,以便其他人可以从中受益

标签: java text split label appcelerator-mobile


【解决方案1】:

不久前我做过类似的事情。下拉推文通过正则表达式运行文本以提取 URL。

我所做的是将每条推文放在一个 tableview 行中,如果正则表达式返回任何内容,则将 tableview 行设置为 hasChild=true,然后 onClick 一个 tableView 行,如果 hasChild == true 打开具有给定 URL 的 webview (存储在行中)。

像这里这样的正则表达式应该可以工作: http://www.geekzilla.co.uk/view2D3B0109-C1B2-4B4E-BFFD-E8088CBC85FD.htm

比如:

str= <<tweet text>>;
re= <<URL expression>>;

check=str.match(re);

现在检查是否包含 null 或 url。

【讨论】: