Domanda

I am using knockout-validation for validation. I need to find all the observable variables which are invalid.

How can I find that?

please help.

thanks

È stato utile?

Soluzione

var invalidObservables = {};
for ( var prop in viewModel ) {
    if ( viewModel.hasOwnProperty( prop ) && ko.isObservable( viewModel[ prop ] ) ) {
        if ( viewModel[ prop ].hasOwnProperty( 'isValid' ) && !viewModel[ prop ].isValid() ) {
            invalidObservables[ prop ] = viewModel[ prop ];
        }
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top