mardi 11 août 2020

knockout.js - how to check if a variable has a certain value

I have to check if a variable equals a certain string e.g.

if (product_type == "simple") { ... }

How can I do this in knockout.js? I have read the documentation, but not sure where to look.

Attempt:

<!-- ko if: is_product_type && product_type == "simple" -->
<div class="primary">
    <a data-bind="attr: {href: configure_url, title: $t('foo')}" class="action edit">
        <span data-bind="i18n: 'Edit'"></span>
    </a>
</div>
 <!-- ko else: -->
<div class="primary">
    <a data-bind="attr: {href: configure_url, title: $t('bar')}" class="action edit">
        <span data-bind="i18n: 'Edit'"></span>
    </a>
</div>
<!-- /ko -->

↑ does not work, it renders both.

Aucun commentaire:

Enregistrer un commentaire