Knockout asyncCommand - 从方法中命中
Knockout asyncCommand - hit from a method
我想更改 asyncCommand 的命中方式(目前是通过按钮),因此我需要从代码访问 asyncCommand。我不想改变这个 asyncCommand 在做什么,它正在处理付款细节。
我试过谷歌搜索但我找不到任何东西,我也是KO的新手
这就是我要实现的目标:
- 单击一个按钮(一个单独的按钮,它有自己的 asyncCommand 方法
检查标志) 'execute' 将执行以下操作:
如果(标志)- 显示模式
- 模态有两个选项 - 继续/取消
- 如果继续 - 为原始按钮(卡支付一)点击 asyncCommand 命令。
- 如果取消 - 返回表单
如果 (!flag)
- 为原始按钮(卡支付一)命中 asyncCommand 命令。
这可以做到吗?
在此先感谢您的帮助。
克莱尔
这是我试过的:
第一个按钮
model.checkAddress = ko.asyncCommand({
execute: function (complete)
{
makePayment.execute();
if (data.shippingOutOfArea === true || (data.shippingOutOfArea === null && data.billingOutOfArea === true)) {
model.OutOfArea.show(true);
}
complete();
},
canExecute: function (isExecuting) {
return !isExecuting;
}
});
原始按钮
model.makePayment = ko.asyncCommand({
execute: function (complete) {
}})
模态
model.OutOfArea = {
header: ko.observable("Out of area"),
template: "modalOutOfArea",
closeLabel: "Close",
primaryLabel: "Continue",
cancelLabel: "Change Address",
show: ko.observable(false), /* Set to true to show initially */
sending: ko.observable(false),
onClose: function ()
{
model.EditEmailModel.show(false);
},
onAction: function () {
makePayment.execute();
},
onCancel: function ()
{
model.EditEmailModel.show(false);
}
};
对于这种情况,您实际上将有两个异步命令。一个打开模态,一个打开模态
例如:
showPaymentPromptCmd = ko.asyncCommand({
execute: function(complete) {
if (modalRequired) {
showModal();
} else {
makePayement();
}
complete();
},
canExecute: function(isExecuting) {
return !isExecuting;
}
});
//Called by Continue button on your modal.
makePaymentCmd = ko.asyncCommand({
execute: function(complete) {
makePayement();
complete();
},
canExecute: function(isExecuting) {
return !isExecuting;
}
});
var
function makePayement() {
//some logic
}
我想更改 asyncCommand 的命中方式(目前是通过按钮),因此我需要从代码访问 asyncCommand。我不想改变这个 asyncCommand 在做什么,它正在处理付款细节。
我试过谷歌搜索但我找不到任何东西,我也是KO的新手
这就是我要实现的目标:
- 单击一个按钮(一个单独的按钮,它有自己的 asyncCommand 方法 检查标志) 'execute' 将执行以下操作:
如果(标志)- 显示模式
- 模态有两个选项 - 继续/取消
- 如果继续 - 为原始按钮(卡支付一)点击 asyncCommand 命令。
- 如果取消 - 返回表单
如果 (!flag)
- 为原始按钮(卡支付一)命中 asyncCommand 命令。
这可以做到吗?
在此先感谢您的帮助。
克莱尔
这是我试过的: 第一个按钮
model.checkAddress = ko.asyncCommand({
execute: function (complete)
{
makePayment.execute();
if (data.shippingOutOfArea === true || (data.shippingOutOfArea === null && data.billingOutOfArea === true)) {
model.OutOfArea.show(true);
}
complete();
},
canExecute: function (isExecuting) {
return !isExecuting;
}
});
原始按钮
model.makePayment = ko.asyncCommand({
execute: function (complete) {
}})
模态
model.OutOfArea = {
header: ko.observable("Out of area"),
template: "modalOutOfArea",
closeLabel: "Close",
primaryLabel: "Continue",
cancelLabel: "Change Address",
show: ko.observable(false), /* Set to true to show initially */
sending: ko.observable(false),
onClose: function ()
{
model.EditEmailModel.show(false);
},
onAction: function () {
makePayment.execute();
},
onCancel: function ()
{
model.EditEmailModel.show(false);
}
};
对于这种情况,您实际上将有两个异步命令。一个打开模态,一个打开模态
例如:
showPaymentPromptCmd = ko.asyncCommand({
execute: function(complete) {
if (modalRequired) {
showModal();
} else {
makePayement();
}
complete();
},
canExecute: function(isExecuting) {
return !isExecuting;
}
});
//Called by Continue button on your modal.
makePaymentCmd = ko.asyncCommand({
execute: function(complete) {
makePayement();
complete();
},
canExecute: function(isExecuting) {
return !isExecuting;
}
});
var
function makePayement() {
//some logic
}