Json Foreach With Condition [英] Json Foreach With Condition

查看:65
本文介绍了Json Foreach With Condition的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Json有疑问。



我有36个数组的Json数据。



每个这些数组都有3个属性。 (MonthValue,CountValue,TypeValue)。



我想带条件给我带来



只有结果那个typeValue是2.



这是我的整个代码





< pre lang =Javascript> $( function (){
$ .ajax({
type:' POST'
dataType:' json'
contentType:' application / json'
url:' @ Url.Action(GetProviderReport)'
数据:' {}'
成功:功能(结果){


调试器;
var data = new google.visualization.DataTable();
data.addColumn(' number' ' CountValue');
data.addColumn(' number' ' MonthValue');

for var i = 0 ; i< result.length; i ++){

data.addRow([result [i] .CountValue,result [i] .MonthValue]);
}
调试器;
var chart = new google.visualization.AreaChart( document .getElementById(' chartdiv3'));

解决方案

function (){

.ajax({
type:' POST'
dataType:' json'
contentType:' application / json'
url:' < span class =code-string> @ Url.Action(GetProviderReport)',
data:' {}'
成功:功能(结果){


调试器;
var data = new google.visualization.DataTable();
data.addColumn(' number'' CountValue');
data.addColumn(' number' ' MonthValue');

for var i = 0 ; i< result.length; i ++){

data.addRow([result [i] .CountValue,result [i] .MonthValue]);
}
调试器;
var chart = new google.visualization.AreaChart( document .getElementById(' chartdiv3'));


最好按照评论中的说明处理此服务器端。您可以将typeValue作为方法GetProviderReport的参数,这样您也可以将其重用于其他typeValues。



在foreach中你需要一个if语句,因为如果条件为假,foreach中的条件将完全终止循环。



祝你好运!


I have question about Json .

I have Json data that is 36 array .

each these array have 3 property . (MonthValue,CountValue,TypeValue).

I want To Make Condition that bring me

only result that typeValue is 2.

this my whole code


$(function () {
      $.ajax({
          type: 'POST',
          dataType: 'json',
          contentType: 'application/json',
          url: '@Url.Action("GetProviderReport")',
          data: '{}',
          success: function (result) {


              debugger;
              var data = new google.visualization.DataTable();
              data.addColumn('number', 'CountValue');
              data.addColumn('number', 'MonthValue');

              for (var i = 0; i < result.length; i++) {

                  data.addRow([result[i].CountValue, result[i].MonthValue]);
              }
              debugger;
              var chart = new google.visualization.AreaChart(document.getElementById('chartdiv3'));

解决方案

(function () {


.ajax({ type: 'POST', dataType: 'json', contentType: 'application/json', url: '@Url.Action("GetProviderReport")', data: '{}', success: function (result) { debugger; var data = new google.visualization.DataTable(); data.addColumn('number', 'CountValue'); data.addColumn('number', 'MonthValue'); for (var i = 0; i < result.length; i++) { data.addRow([result[i].CountValue, result[i].MonthValue]); } debugger; var chart = new google.visualization.AreaChart(document.getElementById('chartdiv3'));


It would be best to handle this server side as mentioned in the comments already. You could ass typeValue as a parameter to the method GetProviderReport so you can also reuse it for other typeValues.

In the foreach you would need an if statement because the condition in the foreach would terminate the loop entirely if the condition is false.

Good luck!


这篇关于Json Foreach With Condition的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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