0

I have the an array.

and I have a table:

and this is my template:

What I want to do is for each VegType have 1 checkbox for Carrot, 1 for Potato, 1 one for ETC.

so what will show is :

and so on so forth...

but I want the VegID and VegiType to show next to each check box.

Hope someone helps with this.

Thanks

1
  • Where is your viewmodel code? Try posting this in a fiddle so we can see what is going on. Commented Jul 2, 2012 at 18:47

1 Answer 1

1

It looks to me like you just want another foreach wrapped around the generation of the checkboxes:

<tbody data-bind="foreach: VegType" >
    <label data-bind="text: Vegitype"></label>
    <input type="checkbox" data-bind="attr:{id: VegID}"/>

UPDATE:

Ok, so it looks like you want to do something like:

<script type="text/html" id="a-template">
<tr>
    <td>
    <span data-bind="text: INFOTEXTAREA"></span>
    <textarea></textarea>
    <span data-bind="text: ID"></span>
    <ul data-bind="foreach: VegType">
    <li>
        <label data-bind="text: Vegitype"></label>
        <input type="checkbox" data-bind="attr:{id: VegID}" />
    </li>
    </ul>

</tr>
</script>
Sign up to request clarification or add additional context in comments.

3 Comments

My first foreach will run and create the text on top of the text area and the text area, but each time a text and text area is created.. it will also creat 3 checkboxes Carrot, Potato, ETC. for the same table body.
Thanks this works :) I am just wondering how it recoganizes that VegType is an array inside an array ;/
You're welcome. You defined VegType as an array using the [] syntax so knockout knows :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.