2

sup guys, my english is not good.. but i'll try my best

I'm new with knockout, I'm really impressed with this tool. I'm using this framework on my new page in my MVC 3 application. But i just faced a problem on how to mark my checkboxlist with data from the database.

<div data-bind="foreach: listPeople">
    <div>
        <label>
            <input type="checkbox" data-bind="attr: { value: id_person}, checked: $parent.checkedPeople "  />
            <span data-bind="text: name_person"></span>
        </label>
    </div>
</div>

as u guys can see, im using the checked tag to "hold" the id_person information to save im my database.

listPeople is an observableArray with my people. and checkedPeople is an observableArray with those chosed people.

while inserting its working like a piece of cake. the problem is when im tryin to "edit". When i try to previous populate "checkedPeople".

isnt knockout supposed to recognize it ?

Jaime Yule
  • 981
  • 1
  • 11
  • 20
  • im tryin and searching a way to solve it size yesterday.. i only found people using static data like this one http://jsfiddle.net/ducka/haq2y/ – Jaime Yule May 14 '12 at 19:46

1 Answers1

0

I am trying to understand your question here. Do you mean to say that the list is binding with the people, but doesn't check the chosen people appropriately? If that's the case, your chosenPeople observable array needs to be an array of integers (not of type People).

The value of the checkbox needs to match at least one of the integers in the chosenPeople array for it to appear as checked.

Paolo del Mundo
  • 2,121
  • 13
  • 18
  • its a bug.. this value: id_person is a "string" field.. i solved the problem in my JS (ModelView) with this: for (var i in result.checkedList) self.checkedPeople().push(result.checkedList[i].id_person.toString()); i just changed the type of my array from int to string. – Jaime Yule May 15 '12 at 14:29
  • but now.. by some mistake i need to make a knockout action to make my checkboxlist recognize that it have already some checked people. I have to check one. then knockout "omg there's already some checkbox that need to be marked". – Jaime Yule May 15 '12 at 14:33