【发布时间】:2013-12-25 13:40:24
【问题描述】:
我的父和根绑定有问题。
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>
我无法使用 click: $parent.RemoveExpr1" 调用函数 self.RemoveExpr1 你有什么想法如何解决这个问题
【问题讨论】:
-
用
$root.RemoveExpr1怎么样?
标签: knockout.js knockout-2.0 knockout-mvc knockout-sortable