javascript - Knockout JS overwriting all values with the last value in foreach binding -
in knockoutjs app, looping on observable array , displaying stuff this:
<div id="user-list-container" data-bind="foreach: users"> <div class="row order-line list-row"> <div class="medium-7 small-10 columns"> <i class="fi-torso tip-right"></i> <a href="javascript:void(0)" data-bind="text: user().name"></a> <a href="javascript:void(0)" data-bind="text: accountid"></a> </div> <div class="medium-3 columns"> <a href="#" class="button split tiny info radius"> <i data-bind="text:role"></i> <span data-dropdown="leftdrop" data-options="align:left"></span> </a> </div> <div class="medium-2 small-2 columns"> <a href="javascript:void(0)" data-bind="click: $root.deleterole"><i class="fi-trash" title="@texts.remove"></i></a> </div> <ul id="leftdrop" class="f-dropdown" data-dropdown-content> <li><a href="#" data-bind="click: $root.makeforeman">foreman</a></li> <li><a href="#" data-bind="click: $root.makeworker">worker</a></li> </ul> </div> </div>
everything works fine , elements shown, when click 1 item operate on particular item, each item has value of last item in array.
in javascript function:
self.makeworker = function (user) { var project = self.selectedproject(); var account = self.accounts.findbykey(user.accountid); var ur = user; console.log(user); console.log(this); if (project.role() != "worker") { var data = { role: "worker", organizationid: project.organizationid, projectid: project.id, accountid: user.accountid } tippnett.project.changerole(data, function (result) { project.users.findbykey(user.id).role("worker"); ur.role("worker"); account.roles.findbykey(user.id).role("worker"); }); } }
the value passed function last value in 'users' observable array.
any input on why happening? see image more briefing:
Comments
Post a Comment