AngularJS:在文本输入中使用If条件

时间:2014-07-07 11:13:31

标签: asp.net-mvc angularjs

我有一个输入类型作为文本来选择日期,我希望它的默认值应该是具有以下结构的JSON数据中最早的:

testData=
{
  "name":"ABC", transactions:[
  {"tranid":01,"trandate":"01/02/2010"},
  {"tranid":02,"trandate":"01/02/2012"}
  ]
}

我想迭代交易并在文本输入中删除最早的日期(即01/02/2010)

请协助如何以角度进行操作。

2 个答案:

答案 0 :(得分:0)

嗨,请看这里:http://jsbin.com/reyog/1/edit

function finderliest()
  {    
        angular.forEach(testData.transactions, function(transaction){

       if($scope.erliest === undefined || transaction.trandate < $scope.erliest ){
             $scope.erliest = transaction.trandate;

      }
    });

  };

答案 1 :(得分:0)

var len=testData.transactions.trandate.length;
if(len>0)
{
      for (i=0;i<len;i++)
     {
        for (j=1;j<len;j++)
        {
            var dateone=testData.transactions.trandate[i];
            var datetwo=testData.transactions.trandate[j];

            //(use this logic or else logic whichever you like) http://www.c-sharpcorner.com/UploadFile/8911c4/how-to-compare-two-dates-using-javascript/


        }
      }
}