如何使用Angular Schema Form Checkbox boolean处理onChange? [英] How to handle onChange with Angular Schema Form Checkbox boolean?

查看:81
本文介绍了如何使用Angular Schema Form Checkbox boolean处理onChange?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法解决这个onChange事件。我已根据文档将该方法添加到代码中,但没有发生任何事情。

I can't seem to get this onChange event to fire. I have added the method to the code as per the documentation but nothing is happening.

 $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

Check out this plunker: http://plnkr.co/edit/XJGuPYPBDc7520vjWtbI?p=preview

推荐答案

周五想出这个。我需要在表单定义中按键引用每个属性。

Figured this one out Friday. I need to reference each property by key in the form definition.

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

Reference the updated 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"
}
];

这篇关于如何使用Angular Schema Form Checkbox boolean处理onChange?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆