1

我正在尝试实现如图所示的过滤器。我正在使用 Angular JS 框架,JQuery。

要求是,我有复选框过滤器,如应用程序名称、状态等。在选择应用程序或状态时,我需要动态创建 JSON,如下所示。“filterValues”中的值应根据复选框值自动添加或删除。

根据 json 值,我将查询数据库并获取结果并显示。

我正在构建如下所示的复选框:

<div class="row-fluid">
<div ng-repeat="status in keywords.kw_Status">
    <label class="checkbox">
        <input type="checkbox" value="{{status}}" ng-model="isChecked" ng-change="change('Status','txt_Status',status,isChecked)">{{status}}
    </label>
</div>

对应的控制器代码如下

$scope.change=function(filterCategory, filterField, filterValue, filterAdd){
$scope.filters[filterCategory]={"filterField":filterField,"filterValues":[filterValue]};
console.log($scope.filters);

}

任何帮助深表感谢!!

我正在尝试实现如图所示的过滤器

{
"Region": {
    "filterField": "kw_Region",
    "filterValues": [
        "aa",
        "bb"
    ]
},
"ApplicationName": {
    "filterField": "kw_ApplicationName",
    "filterValues": [
        "aa",
        "bb"
    ]
},
"IssueType": {
    "filterField": "kw_IssueType",
    "filterValues": [
        "aa",
        "bb"
    ]
},
"Outage": {
    "filterField": "kw_Outage",
    "filterValues": [
        "aa",
        "bb"
    ]
},
"Priority": {
    "filterField": "kw_Priority",
    "filterValues": [
        "aa",
        "bb"
    ]
}

}

4

1 回答 1

0

“filterValues”中的值应根据复选框值自动添加或删除。

使用 JSON.stringify 和替换回调来实现这一点:

function replacer(match, offset, fullstring)
  {
  return replacer.str;
  }

replacer.str = "\u0022filterValues\u0022:[\u0022hi\u0022,\u0022bye\u0022]"; /* Use DOM node value */

var foo = JSON.stringify({
"Region": {
    "filterField": "kw_Region",
    "filterValues": [
        "aa",
        "bb"
    ]
},
"ApplicationName": {
    "filterField": "kw_ApplicationName",
    "filterValues": [
        "aa",
        "bb"
    ]
},
"IssueType": {
    "filterField": "kw_IssueType",
    "filterValues": [
        "aa",
        "bb"
    ]
},
"Outage": {
    "filterField": "kw_Outage",
    "filterValues": [
        "aa",
        "bb"
    ]
},
"Priority": {
    "filterField": "kw_Priority",
    "filterValues": [
        "aa",
        "bb"
    ]
}
}).replace(/"filterValues[^\]]+./g, replacer)
于 2013-12-06T02:09:16.203 回答