javascript - strange "not defined" error -
i have below code in viewmodel:
ca = function (clientnum) { this.caname = null; this.caadress = null; this.caidnum = null; this.cacontact = null; this.canote = null; this.catype = null; this.clnum = clientnum; }, viewmodelnewcredit = function () { var creditrows = ko.observablearray(), showview = ko.observable(), sessionticket = ko.observable(), loggeduser = ko.observable() newcreditrows = function () { console.log(this.clientnum()); this.creditrows.push(new ca(this.clientnum())); console.log(creditrows()); }, remove = function (ca) { this.creditrows.remove(ca); }; return { creditrows: creditrows, showview: showview, sessionticket: sessionticket, loggeduser: loggeduser, viewmodelnewcredit: viewmodelnewcredit, remove: remove }; },
and in html have:
<tbody data-bind="foreach: creditrows"> <tr> <td> <select name="catype" id="catype" data-bind="value: catype" style="width: 8em;"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> </select> </td> <td> <input type="text" name="caname" id="caname" data-bind="value: caname" style="width: 15em;"> </td> <td> <input type="text" name="caadress" data-bind="value: caadress" style="width: 15em;"> </td> <td> <input type="text" name="caidnum" data-bind="value: caidnum" style="width: 6em;"> </td> <td> <input type="text" name="cacontact" data-bind="value: cacontact" style="width: 10em;"> </td> <td> <input type="text" name="canote" data-bind="value: canote" style="width: 15em;"> </td> <td> <img src="/projmonitoring/js/images/close.jpg" alt="close" data-bind="click: remove.bind($parent)"> </td> </tr> </tbody> </table> <button type="button" id="newrow" class="button" data-bind="click: newcreditrows">add new row</button> <button type="button" id="openmodal" class="button" data-bind="click: openmodal">open modal</button>
this line of code: <img src="/projmonitoring/js/images/close.jpg" alt="close" data-bind="click: remove.bind($parent)">
supposed execute function, i'm getting is:
error: unable parse bindings. message: referenceerror: remove not defined; bindings value: click: remove.bind($parent)
do have idea going on? i'm pretty sure i'm missing small, i'm not able spot it.
you in context of foreach, when calling remove method, trying call on element array traversing. instead need call on viewmodel:
<img src="/projmonitoring/js/images/close.jpg" alt="close" data-bind="click: $root.remove">
Comments
Post a Comment