knockout.jsjquery-ui-sortableknockout-sortable

Knockout-sortable - Multiple Elements In List Item


I am working off of the following example jsfiddle and changed it to this jsfiddle

I am attempting to change it to allow multiple elements bound to an object in an array, however no matter what I do, only the first element with data-bind is rendered. I am sure that I am using it wrong, however I do not understand why I am wrong.

Shouldn't the following render two labels, the first with the name and the second with the ID?

<div class="list">
    <h2>Stored procedures In DB 2</h2>
    <ul class="list" id="sortableForDB_2" data-bind="sortable: storedProceduresInDB2">
        <li><div><label class="item" data-bind="text: Name" />
                 <label class="item" data-bind="text: Id" /></div></li>
    </ul>
</div>

Thank you in advance

Edit 1: By the way, it is definitely something to do with the data-bind as the following works just fine:

<div class="list">
    <h2>Stored procedures In DB 2</h2>
    <ul class="list" id="sortableForDB_2" data-bind="sortable: storedProceduresInDB2">
        <li><div><label>1</label>
                 <label>2</label></div></li>
    </ul>
</div>

Solution

  • The label element must be correctly formed for the bindings to work - ie it must have a closing tag:

    <div class="list">
        <h2>Stored procedures In DB 2</h2>
        <ul class="list" id="sortableForDB_2" data-bind="sortable: storedProceduresInDB2">
            <li><div><label class="item" data-bind="text: Name"></label>
                <label class="item" data-bind="text: Id"></label></div></li>
        </ul>
    </div>
    

    Updated fiddle

    Regarding the correct formation of the label element:

    Tag omission: None, both the starting and ending tag are mandatory.