私はエクステンダーを使用しようとしてマッピング・プラグインで(と思う)いくつかの問題がありました。私は唯一の日付を表示し、それらを許可しないよので、私はちょうどこのような結合ハンドラを使用することを好む編集する:
ko.bindingHandlers.date =
{
update: function (element, valueAccessor:() => any, allBindingsAccessor: any)
{
return ko.bindingHandlers.text.update(element, function()
{
var value: any = ko.utils.unwrapObservable(valueAccessor());
if (value == null)
{
return null;
}
if (typeof value === "string")
{
value = new Date(value);
}
return value.toShortDateString();
}, allBindingsAccessor, null, null);
}
};
私がプロトタイプを追加することにしました。ここでは
Shipped on <span data-bind="date: shipDt"></span>
をハンドラですこのようなDateオブジェクト(ハンドラで作成されたDateオブジェクトのtoShortDateString
) - しかし、上記のロジックをGlobalize
などで置き換えることができます。
Date.prototype.toShortDateString = function()
{
return (this.getMonth() + 1) + "/" + this.getDate() + "/" + this.getFullYear();
};
あなたが観測可能で 'date'オブジェクトまたは文字列を「保存しています2013- 06-17T11:56:18.4537687Z "? – nemesv