Knockout Mapping Validation

后端 未结 2 498
梦毁少年i
梦毁少年i 2020-12-28 16:39

I\'m trying to attach validation to a mapped view. I\'m using Knockout Mapping and Validation plugins. Pseudo-models:

Person {
    int Id;
    string Name;
          


        
2条回答
  •  爱一瞬间的悲伤
    2020-12-28 17:08

    Another way is to extend the observable after it has mapped.

    function viewModel() {
        var self = this;
        self.persons = ko.observableArray();
    
        // persons are retrieved via AJAX...
        ko.mapping.fromJS(persons, {}, self.persons);
    
    
        self.Name.extend({ required: true });
    }
    

提交回复
热议问题