Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy knockoutjs js doesn't update view in case some sub array is changed
    primarykey
    data
    text
    <p>I have next model wirt sub array</p> <pre><code>&lt;!-- ko foreach: {data: userAdminView.viewRoles, as: 'rrole'} --&gt; &lt;tr&gt; &lt;td class="userRolesRoleTitle"&gt;&lt;b data-bind="text: rrole.role.name"&gt;&lt;/b&gt;&lt;br/&gt;&lt;i data-bind="text: rrole.role.description"&gt;&lt;/i&gt;&lt;/td&gt; &lt;td class="userRolesRoleGroups"&gt; &lt;!-- ko foreach: {data: rrole.role.groups, as: 'group'} --&gt; &lt;div class="usersGroupElement" data-bind="html: group.viewName"&gt;&lt;/div&gt; &lt;!-- /ko --&gt; &lt;a class="btn emb green" data-bind="click: userAdminView.addNewGroup,visible:(rrole.role.isNewGroupAccessible) , attr: { value: rrole }"&gt;&lt;i class="icon16 plus"&gt;&lt;/i&gt;add&lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;!-- /ko --&gt; </code></pre> <p>it working well, but from bussines needs I need change dynamictly data in <strong>rrole.role.groups</strong> sub-array. My code is working and do it, I see that array is changed (added, remove element) in debug mode, but view is updated only if <strong>userAdminView.viewRoles</strong> array get changes. Why knockoutjs dos't mange it. How I can fix it ?</p> <pre><code>function userAdminView(user) { var self = this; self.viewRoles = ko.observableArray([]); self.saveNewGroup = function (data, event) { var datar = self.viewRoles(); $.each(datar, function (index, vrole) { if (vrole.role.id == self.dialogRole.role.id) { var line = { viewName: "&lt;b&gt;" + self.dialogCustomer.name + "&lt;/b&gt;", customer: self.dialogCustomer, department: self.dialogDepartment, isEdit: true }; if (vrole.role.groups == null) { vrole.role.groups = []; } vrole.role.groups.push(line); } }); }; } </code></pre> <p>data structure:</p> <pre><code>{ role: { description: role.description, id: role.id, name: role.name, groups: existingGroups, isNewGroupAccessible: self.canGrant(role, data.d) } }; </code></pre> <p>Thanks. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload