Pregunta

Estoy tratando de establecer algún contenido en una plantilla que sea visible solamente si el artículo que se queden es el "elemento actual".

Aquí está el código hasta el momento, quiero ser capaz sólo de hacer que una parte de la plantilla interior si el elemento de datos que se queden ha ID == window.viewModel.activeObject.

<section data-bind='template: { name: "categoryTemplate", foreach: categories }'></section>

<script type="text/html" id="categoryTemplate">
    <section>
        <h2>${Name}</h2>
        <section data-bind='template: { name: "objectTemplate", foreach: Objects }'></section>
    </section>
</script>
<script type="text/html" id="objectTemplate">
    <article>
        <h3>${Name}</h3>

      (only render this if the object rendered has ID equal to viewModel.activeObject)
        {{html Text}}

    </article>
</script>
<script>
    $(document).ready(function(){
        window.viewModel = { categories : <asp:Literal runat="server" ID="LiteralJSON" />,
            activeCategory: ko.observable(0),
            activeObject: ko.observable(0)
        };

        ko.applyBindings(window.viewModel);
    });
</script>

¿Cómo voy a ir haciendo eso?

¿Fue útil?

Solución

querrá usar {if}{/if}

<script type="text/html" id="objectTemplate">
    <article>
        <h3>${Name}</h3>
        {if $item.data.id === viewModel.activeObject()}
        {{html Text}}
        {/if}
    </article>
</script>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top