我有一個父級和根綁定的問題。敲除父級和根綁定
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:$ parent.RemoveExpr1" 你有什麼想法如何解決這個問題
如何使用'$ root.RemoveExpr1'? –
是的,它的工作。謝謝。 – user3044918