2016-08-05 48 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 ...你回答下一個不同的帳戶你自己的問題? –