选中ui-grid angular js中的复选框

时间:2016-02-04 19:12:48

标签: angularjs angular-ui-grid

在我的项目中使用ui-grid,我从DB获取JSON对象,如下面

[
    {
        "checkbox1": {
            "fieldName": "checkbox1",
            "fieldValue": "Y"
        },
        "checkbox2": {
            "fieldName": "checkbox3",
            "fieldValue": "Y"
        },
        "checkbox3": {
            "fieldName": "checkbox3",
            "fieldValue": "N"
        }
    }
]

下面的对象是columnDef

[
    {
        "name": "checkbox1",
        "field": "checkbox1.fieldValue",
        "displayName": "checkbox1",
        "cellTemplate": '<input type=\"checkbox\" ng-model=\"{{COL_FIELD}}\" ng-true-value=\'Y\' ng-false-value=\'N\' />'
    },
    {
        "name": "checkbox2",
        "field": "checkbox2.fieldValue",
        "displayName": "checkbox2",
        "cellTemplate": '<input type=\"checkbox\" ng-model=\"{{COL_FIELD}}\" ng-true-value=\'Y\' ng-false-value=\'N\' />'
    },
    {
       "name": "checkbox3",
        "field": "checkbox3.fieldValue",
        "displayName": "checkbox3",
        "cellTemplate": '<input type=\"checkbox\" ng-model=\"{{COL_FIELD}}\" ng-true-value=\'Y\' ng-false-value=\'N\' />'
    }
];

渲染html后,我在控制台中收到错误:

  

Error: [$parse:syntax] http://errors.angularjs.org/1.5.0-rc.1/$parse/syntax?p0=%7B&p1=invalid%20key&p2=2&p3=%7B%7Bgrid.getCellValue(row%2Col)%7D%7D&p4=%7Bgrid.getCellValue(row%2C%col)%7D%7D

如何解决此问题?

2 个答案:

答案 0 :(得分:2)

http://ui-grid.info/docs/#/tutorial/201_editable

尝试使用'boolean'类型而不是'checkbox'

答案 1 :(得分:0)

ng-true-value="'Y'"fscanf()都希望传递表达式。当你想传递一个字符串时,它应该像:int person_read(FILE *file, struct person *person) { // Warning: if names contain spaces "%255s%d" will not work if (fscanf(file, "%255s%d", person->name, person->age) != 2) { fprintf(stderr, "warning: invalid read!\n"); return -1; } return 0; } 一样传递。

来自NG文档的示例:https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D

尝试更正您的细胞模板以适应此情况。

相关问题