0

ページでノックアウト js ビュー モデルを使用していますが、jquery ダイアログに設定した div にあるクリック バインディングを除いて、すべてが正常に機能します。

ここにdivがあります

<div id="CancelModal" title="Cancel">
    Changes to the definition have been detected. Do you want to exit and discard    the changes?"   
    <div style="position: absolute; bottom: 8px; right: 8px; text-align: right">
        <input type="button" value="Yes" data-bind="click: cancelConfirm" />
        <input type="button" value="No" data-bind="click: cancelDeny" />
    </div>
</div>

それから私のjquery

$("#CancelModal").dialog({
    modal: true,
    autoOpen: false,
    width: 400,
    minHeight: 150,
    maxHeight: 150,
    position: "center",
    resizable: false
});

次に、私が持っているビューモデルで

...

cancelConfirm() {
    alert("confirm");
}

cancelDeny() {
    alert("deny");
}

バインディングは設定されていますが、このダイアログの要素に対してのみ機能していません。jquery ダイアログ コードを削除すると、機能します。ここで何をする必要があるか考えていますか?

4

2 に答える 2

1

これを試してくださいhttp://jsfiddle.net/76EEt/1/

HTML

<a href="#" data-bind="click: $root.openDialog"> Open dialog </a> 
<div id="CancelModal" title="Cancel">
    Changes to the definition have been detected. Do you want to exit and discard    the changes?"   
    <div style="position: absolute; bottom: 8px; right: 8px; text-align: right">
        <input type="button" value="Yes" data-bind="click: cancelConfirm" />
        <input type="button" value="No" data-bind="click: cancelDeny" />
    </div>
</div>

JS

$("#CancelModal").dialog({
    modal: true,
    autoOpen: false,
    width: 400,
    minHeight: 150,
    maxHeight: 150,
    position: "center",
    resizable: false
});

var DataViewModel = function() {
    var self = this;

    self.cancelConfirm = function () {
         alert("confirm");
    };

    self.cancelDeny = function () {
         alert("deny");
    };

    self.openDialog = function () {
        $("#CancelModal").dialog("open");
    };
};

ko.applyBindings(new DataViewModel());
于 2013-07-19T20:50:40.127 に答える
0

関数と等しくなるように変更する必要があります

self.cancelConfirm = function() {
    alert("confirm");
}

or 

this.cancelConfirm = function() {
    alert("confirm");
}
于 2013-07-19T20:50:55.740 に答える