2016-08-05 59 views
2

我似乎无法将此onChange事件触发。我已经按照文档将该方法添加到代码中,但没有任何事情发生。如何使用Angular Schema格式处理onChange复选框boolean?

$scope.schema = { 
"type": "object", 
"title": "Comment", 
"properties": { 
    "comment": { 
    "type": "array", 
    "items": { 
     "type": "object", 
     "properties": { 
     "name": { 
      "type": "boolean", 
      "title": "Name" 
     }, 
     "eligible": { 
      "type": "boolean", 
      "title": "Eligible for awesome things" 
     }, 
     "code": { 
      "type":"boolean", 
      "title": "The Code" 
     } 
     } 
    } 
    }, 
    "comment2": { 
    "type": "boolean", 
    "title": "Name" 
    } 
}, 
"required": [ 
    "comment" 
] 
}; 


$scope.form = [ 
{ 
    key: "comment", 
    onChange: function(model, form){ 
    console.log('got there though'); 
    } 
}, 
{ 
type: "boolean", 
onChange: function(model, form){ 
    console.log('this'); 
} 
}, 
{ 
    type: "submit", 
    title: "Save" 
} 
]; 

$scope.model = {}; 

看看这个plunker:http://plnkr.co/edit/XJGuPYPBDc7520vjWtbI?p=preview

回答

1

想通这一个星期五。我需要通过表单定义中的键引用每个属性。

参考更新plunker:http://plnkr.co/edit/XJGuPYPBDc7520vjWtbI?p=preview

$scope.form = [ 
{ 
    key: 'comment', 
    add: null, 
    remove: null, 
    title: false, 
    notitle: true, 
    items: 
    [ 
    { 
     key: "comment.name", 
     title: 'This', 
     type: 'boolean', 
     onChange: function(model, form){ 
     alert('got there ' + model.toString()); 
     } 
    }, 
    { 
     key: "comment.elgible", 
     title: 'This', 
     type: 'boolean', 
     onChange: function(model, form){ 
     alert('got there though'); 
     } 
    }, 
    { 
     key: "comment.code", 
     title: 'This', 
     type: 'boolean', 
     onChange: function(model, form){ 
     alert('got there though'); 
     } 
    }, 
    ] 
}, 

{ 
    type: "submit", 
    title: "Save" 
} 
]; 
+0

泰勒·琼斯.... tjones ...你回答下一个不同的帐户你自己的问题? –