Results 1 to 4 of 4

Thread: How to interpolate a variable in a .html element?

  1. #1

    Default Answered: How to interpolate a variable in a .html element?

    Hi I have a question, I am very confused about this subject and if I am completely barking up the wrong tree then please let me know.

    So I have a carousel component with a number of cards in it, I want to be able to display some text in each card based on data that is stored in a global variable.

    As I understand it the correct way to populate a card is to use the .html function e.g.

    Code:
    {                        html: 'Content 2'
                            style: 'background:#333'
                  }
    What I am trying to do is produce a piece of code that will be rendered in that .html section to display the contents of a variable , the variable in this case is contained here and is valid

    Code:
    AccessAber.app.getSelectedRoute().route_name_en
    I assumed that I would be able to use {} or [] brackets to access this value inside the HTML but it either does not run, or gives me an error saying the variable is null at compile time, which is true as the variable is not set until run time and as such I would not expect this .html element to be rendered until the user reaches that screen in the hierarchy.

    This is the approach that I would assume would work but it does not, it gives the error about the variable being null, which as mentioned above it should be at this point until the view is rendered.

    Code:
    "<h2>routename: " + AccessAber.app.getSelectedRoute().route_name_en + "</h2>"
    Am I missing something simple here? This seems like it should be incredibly trivial...

    Thanks

    Jonathan

  2. Hey, did you try to use setHtml?
    try this:
    Code:
    <your container>.setHtml('<h2>routename: ' + AccessAber.app.getSelectedRoute().route_name_en + '</h2>');

  3. #2
    Sencha Premium Member
    Join Date
    Sep 2012
    Location
    Israel
    Posts
    122
    Answers
    3

    Default

    Hey, did you try to use setHtml?
    try this:
    Code:
    <your container>.setHtml('<h2>routename: ' + AccessAber.app.getSelectedRoute().route_name_en + '</h2>');

  4. #3

    Default Yay

    You did it!

    That worked.

    It is strange that you cannot use that same code without accessing the setter function, surely the view is only rendered at run time, in my case it isn't seen by a user until that variable is ready. Strange

    Thanks again!

    JF

  5. #4
    Sencha Premium Member
    Join Date
    Sep 2012
    Location
    Israel
    Posts
    122
    Answers
    3

    Default

    It's sencha's way of accessing variables, I find it pretty comfortable, it is also safer because you won't be accessing values you're not supposed to...on the other hand if you really just want to access html without using setHtml you could with a some inspection of your object, but again you shouldn't

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •