Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Display resultset (text) within a label, multiline

I´m actually trying to fetch some data from the underlying sqlite database on iPhone platform. This does work pretty well, indeed.

This works for simple text only. Multiline (with \n and \r) does not.

Does someone know how to solve this, how to make text coming from database come out as multi-line text?

Any help is much appreciated!

— asked September 9th 2010 by Florian Dehn
  • database
  • label
  • line
  • multiline
  • new
  • resultset
  • text
  • titanium.ui.label
0 Comments

5 Answers

  • did u set this?

    label.height = 'auto'
    
    — answered September 9th 2010 by Haoming Cheng
    permalink
    0 Comments
  • Found an answer to my problem.

    Though, it´s a quite simple (and dirty!) … call it a hack :)

    function evalStrings(string) {
        eval('result="'+string+'"');
        return result;
    }
    text    = evalStrings(row.fieldByName('simple_text'));
    

    This code should treat some \n and stuff as if you´d write them by hand.
    They come out as expected…

    Please let me know if you have solved this differently.
    Cheers.

    — answered September 14th 2010 by Florian Dehn
    permalink
    1 Comment
    • This solution worked great for me. Thank you for sharing!

      — commented April 2nd 2014 by Vui Nguyen
  • Actually, the correct answer is:

    text = row.fieldByName('simple_text').replace(/\n/g, "\n");

    — answered January 22nd 2011 by Eddie Monge
    permalink
    1 Comment
    • Thx, it's worked!

      — commented November 22nd 2012 by Tamas Bencsik
  • Yes, I did.
    My code as follows:

    var label = Titanium.UI.createLabel({
            text:row.fieldByName('text'),
            height:'auto',
            width:'auto',
            highlightedColor: '#fff',
            top: 10,
            bottom: 10,
            left: 10,
            right: 10,
            font : {
                fontSize : 12
            }
        });
    
    — answered September 9th 2010 by Florian Dehn
    permalink
    1 Comment
    • u can try to edit the content in database.

      — commented September 9th 2010 by Haoming Cheng
  • Any output coming from database seems to be escaped, so that any newlines and carriage returns do not work.
    Does someone know a way to solve this, to make newlines work?

    — answered September 14th 2010 by Florian Dehn
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.