DukeScript & Knockout: Knockout binding conditions ?

10 views
Skip to first unread message

Baltic DukeS

unread,
Aug 6, 2016, 3:06:23 PM8/6/16
to DukeScript
Hi,

I'm on an ongoing project with Dukescript and I would like to evaluate a condition in data-bind  :

simple evaluating:

<span data-bind="text: '19' > 18 ? 'Yes' : 'No'"></span>

Result: Yes

Evaluating:
<span data-bind="text: lebensdauer > 10 ? 'Yes' : 'No'"></span>

with eg. lebensdauer = { 10, 12, 12 } and iterate over that, I got:    Yes, Yes, Yes   

The acutal $data object in the iteration is:

...,"lebensdauer": 10,...
...,"lebensdauer": 12,...
...,"lebensdauer": 12,...

In this case, I have test more condition expressions like
data-bind="enable:lebensdauer&gt;10,click:submitIt"

and more... it doesn't work ... i
t's stupid. Have anyone same issues or a solution?
Thanks in advanced
Andreas.

Jaroslav Tulach

unread,
Aug 7, 2016, 2:45:44 AM8/7/16
to Baltic DukeS, DukeScript
Hello Andreas,
I think this is thanks to behavior of knockout.js. If the expression in data-bind evaluates to type 'function', the knockout invokes it. Thus you can use just 'lebensdauer' and it will in fact to 'lebensdauer()'. However if your expression is more complex, you need to remember to add '()' yourself. Thus in your case it would be:

<span data-bind="text: lebensdauer() > 10 ? 'Yes' : 'No'"></span>

this is somehow described at http://knockoutjs.com/documentation/binding-syntax.html

Or, as you are in DukeScript you can create:

@ComputedProperty static String lebensdauerYesNo(int lebensdauer) {
  return lebensdauer > 10 ? "Yes" : "No";
}

and use

<span data-bind="text: lebensdauerYesNo"></span>

I hope one of these solutions will work for you.
-jt
> --
> You received this message because you are subscribed to the Google Groups "DukeScript" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to dukescript+...@googlegroups.com.
> Visit this group at https://groups.google.com/group/dukescript.
> To view this discussion on the web visit https://groups.google.com/d/msgid/dukescript/4cb57341-7344-49b0-bdee-a3fa8ea361c4%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Andreas Czerniak

unread,
Aug 9, 2016, 10:40:45 AM8/9/16
to Jaroslav Tulach, DukeScript
Hi Jaroslav,

thanks for your advice, it works and I understood now how it works :-)
With 'text: lebensdauer() < 10 ? "Yes" : "No" ' and also with

<span data-bind="visible: pseudo() == $root.owner()">
some content
</span>

Javascript Expressions under


// Andreas.




Von: "Jaroslav Tulach" <jarosla...@gmail.com>
An: "ap...@czerniak.eu" <ap...@czerniak.eu>
CC: "DukeScript" <dukes...@googlegroups.com>
Gesendet: Sonntag, 7. August 2016 08:45:43
Betreff: Re: DukeScript & Knockout: Knockout binding conditions ?
Reply all
Reply to author
Forward
0 new messages