ノックアウト検証プラグインを使用しており、observablearray の日付フィールドを静的な日付と比較しようとしています。私はコードが完全ではないことを知っていますが、ここに私が持っているものがあります-
編集:コードを表示-
<tbody data-bind="foreach: allCertificates">
<tr id="AllCertRow" style="cursor: pointer" data-bind="click: $parent.selectThing, css: { highlight: $parent.isSelected() == $data.lwCertID }">
<td>
<ul >
<li><H5><b><span data-bind=" text: clientName"></span> (<span data-bind=" text: clientNumber"></span>) <span data-bind=" text: borrowBaseCount"></span> Loan(s) </b></H5></li>
Collateral Analyst: <span data-bind=" text: userName"></span>
<br />
Certificate: <span data-bind="text: lwCertID"></span> Request Date: <span data-bind=" text: moment(requestDate).format('DD/MMM/YYYY')"></span>
</ul>
</td>
</tr>
</tbody>
私のビューモデルコード-
var LucasSystemDate = ko.observableArray('4/22/2013');
var allCertificates = ko.observableArray([]);
ko.validation.configure({
registerExtenders: true,
messagesOnModified: true,
insertMessages: true,
parseInputAttributes: true,
messageTemplate: null,
grouping: {
deep: true
}
});
ko.validation.rules['Expired'] = {
validator: function (val, otherVal) {
return val < otherVal;
},
message: 'Request has expired. Please reject and initiate client contact.'
};
var activate = function () {
// go get local data, if we have it
return true;
};
var vm = {
activate: activate,
LucasSystemDate: LucasSystemDate,
allCertificates: allCertificates[
{ lwCertID: '2', clientID: '1EX', requestDate: '7/3/2013 12:34:00 PM', userName: 'Peter Rabbit', statusDescription: 'Submitted', statusCode: '1', statusDesc: 'Submitted', clientName: 'Test Company 1 ', clientNumber: '1EX', borrowBaseCount: '1', advRequestCount: '1', ceoUserName: 'Woodall, Chris' },
{ lwCertID: '5', clientID: '1EX ', requestDate: '7/3/2013 1:00:00 PM', userName: 'Bugs Bunny', statusDescription: 'Submitted', statusCode: '1', statusDesc: 'Submitted', clientName: 'Test Company 2 ', clientNumber: '1EX', borrowBaseCount: '1', advRequestCount: '1', ceoUserName: 'Woodall, Chris' },
{ lwCertID: '6', clientID: '1EX ', requestDate: '7/8/2013 6:31:00 AM', userName: 'Jack Frost', statusDescription: 'Submitted', statusCode: '1', statusDesc: 'Submitted', clientName: 'Test Company 3 ', clientNumber: '1EX', borrowBaseCount: '1', advRequestCount: '1', ceoUserName: 'Woodall, Chris' }
]
}
//NOT SURE HOW TO COMPARE requestDate IN THE allCertificates OBSERVEABLEARRAY TO
//THE LucasSystemDate. IF LucasSystemDate < allCertificates.requestDate
//THEN FAIL VALIDATION AND DISPLAY ERROR MESSAGE. THIS CHECK SHOULD
//BE PERFORMED EACH TIME THE DATA IS INITIALLY LOADED.
上記のコードの最後にあるコメント アウトされたコードの下に、Expired 検証ルールを使用して allCertificates observablearray の requestDate を LucasSystemDate と比較するには、どのコードを入力すればよいでしょうか?