Нокаут родителя и root привязка

У меня проблема с родительским и корневым связыванием.

function SignCell() {
         var self = this;
         self.MathSign = ko.observable("+");
         self.AdditionCell = ko.observable("");
     }     
     function Expression(cell) {
         var self = this;
         self.BaseCell = ko.observable(cell);
         self.AddCell = ko.observableArray([]);
     }

 function Condition(active, expression1, sign, expression2, errMassage) {
     var self = this;
     self.Active = ko.observable(active);
     self.Expression1 = expression1;
     self.Sign = ko.observable(sign);
     self.Expression2 = expression2;
     self.ErrMassage = ko.observable(errMassage);
 }
 var ViewModel = function() {
     var self = this;
     self.ConditionArray = ko.observableArray([
         new Condition(true,new Expression(""),"=",new Expression(""),"")
     ]);     
     self.RemoveExpr1 = function () {
         var i = self.ConditionArray.indexOf(arr);
         self.ConditionArray()[i].Expression1.AddCell.push(new Expression());
     };         
 };

и HTML

<tbody data-bind="foreach: ConditionArray">
    <tr>
      <td><input class="input-small" data-bind="value: Expression1.BaseCell"/> 
             <table>
                <tbody  data-bind="foreach: Expression1.AddCell">
                    <tr>                          
                            <button data-bind="click: $parent.RemoveExpr1" class="btn btn-danger"> <i class="icon-minus-sign icon-white"></i></button>
                        </td>
                    </tr>
                </tbody>
            </table>

я не могу вызвать функцию self.RemoveExpr1, используя click: $parent.RemoveExpr1" У вас есть идеи, как решить эту проблему?

1 ответ

Использование $root.RemoveExpr1 вместо $parent.RemoveExpr1

Вы находитесь во вложенном цикле. Функция, которую вы хотите, прикреплена к ViewModel, Вот $root относится к ViewModel не $parent,

Другие вопросы по тегам