0

I am trying to have a dynamic if linking to a property of a different item in an array.

My current code:

Loader

for (...) {

    var index = this.App.Data.Questions.push({
       ...
    }) - 1;

    if (CompareGuids(this.App.Data.Questions[index].QuestionId, '06EF685A-629C-42A5-9394-ACDEDF4798A5')) {
        this.App.PregnancyQuestionId = index;
    }

Template

{^{if ~root.Data.Questions[~root.PregnancyQuestionId].Response.ResponseText == "true"}}
   {{include #data tmpl="Clinical-History-QuestionWrapper-SingleQuestion"/}}
{{/if}}

It works for the initial loading, but it does not update.

Note I assume I could achieve this with a boolean property in ~root, and then have a $.observable(...).oberserve(...) update this property, but I would prefer to have a direct access.

neo post modern
  • 2,262
  • 18
  • 30

1 Answers1

0

It looks like all you need to do is make sure that you are changing the PregnancyQuestionId observably. Just assigning a value cannot trigger data-linking to update the UI.

You need to write:

$.observable(this.App).setProperty("PregnancyQuestionId", index);

That should then trigger the binding correctly...

BorisMoore
  • 8,444
  • 1
  • 16
  • 27
  • @mrs_sheep - if the above works for you, can you "accept' the reply, so others know it was the 'right answer'. Similarly for other questions you have asked in the past, some of which you never indicated whether the reply worked for you or not... Thanks! – BorisMoore Oct 24 '13 at 21:28
  • It works. I will go through the other questions soon. Thanks for all the amazing and fast support! – neo post modern Oct 25 '13 at 08:43
  • One note for JSON users: The initial value of my `Response.ResponseText` was `"true"` or `"false"`, it later changed to `true` and `false` when modified through jsViews. I wrote a helper to catch this: `bool: function (value) { return value == true || value == "true"; }` – neo post modern Oct 25 '13 at 08:45