问题描述
我想实现如图所示,在过滤器中。我使用的角度JS框架,JQuery的。
要求是,我有复选框过滤器像应用程序的名称,状态等。在选择我需要动态地创建一个JSON象下面这样的应用程序或状态。在filterValues的值应该被自动添加或基于检查框值除去。
基于JSON的价值,我必须查询数据库并获取结果和显示像下面我构建复选框:
< DIV CLASS =排液>
< DIV NG重复=状态keywords.kw_Status>
<标签类=复选框>
<输入类型=复选框值={{状态}}NG-模式=器isCheckedNG变=改变(状态,txt_Status,状态器isChecked)> {{状态} }
< /标签>
< / DIV>
在coressponding控制器code是如下
$ scope.change =功能(filterCategory,filterField,filterValue,filterAdd){
$ scope.filters [filterCategory] = {filterField:filterField,filterValues:[filterValue]};
的console.log($ scope.filters);
}
任何帮助是非常AP preciated !!
{
地区: {
filterField:kw_Region,
filterValues:[
AA,
BB
]
},
应用程序名称:{
filterField:kw_ApplicationName,
filterValues:[
AA,
BB
]
},
IssueType:{
filterField:kw_IssueType,
filterValues:[
AA,
BB
]
},
停电:{
filterField:kw_Outage,
filterValues:[
AA,
BB
]
},
优先: {
filterField:kw_Priority,
filterValues:[
AA,
BB
]
}
}
使用JSON.stringify和替代回调来实现这一点:
函数替代(匹配,偏移,fullstring)
{
返回replacer.str;
}
replacer.str =\ u0022filterValues \ u0022:\ u0022hi \ u0022 \ u0022bye \ u0022]; / *使用DOM节点值* /
无功富= JSON.stringify({
地区: {
filterField:kw_Region,
filterValues:[
AA,
BB
]
},
应用程序名称:{
filterField:kw_ApplicationName,
filterValues:[
AA,
BB
]
},
IssueType:{
filterField:kw_IssueType,
filterValues:[
AA,
BB
]
},
停电:{
filterField:kw_Outage,
filterValues:[
AA,
BB
]
},
优先: {
filterField:kw_Priority,
filterValues:[
AA,
BB
]
}
})代替(/filterValues [^ \] + /克,替代)
I am trying to implement a filter as shown in the image. I am using Angular JS framework, JQuery.
The requirement is , I have check box filter like Application Name , Status etc. On selecting an application or status I need to create a JSON dynamically like below . The value in "filterValues" should be automatically added or removed based on the check box values.
Based on the json value I will query the database and fetch the results and display.
I am constructing check box like below:
<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>
The coressponding controller code is as below
$scope.change=function(filterCategory, filterField, filterValue, filterAdd){
$scope.filters[filterCategory]={"filterField":filterField,"filterValues":[filterValue]};
console.log($scope.filters);
}
Any help is much appreciated!!
{
"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"
]
}
}
Use JSON.stringify and a replacer callback to achieve this:
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)
这篇关于增值JSON子阵列动态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!