AngularJS form and null/empty values

前端 未结 4 925
一整个雨季
一整个雨季 2021-02-15 11:20

I am working with a somewhat dynamic AngularJS form. In other words, I am able to add rows of input fields, etc. So my approach was to start with a $scope.formData

4条回答
  •  孤独总比滥情好
    2021-02-15 12:02

    function replacer(key, value) {
        if (value == "" || value == null) {
           return undefined;
        }
      return value;
    }
    
    var foo = {foundation: "", model: {year: 2015, price:null}, week: 45, transport: "car", month: 7};
    foo = JSON.stringify(foo, replacer);
    foo =JSON.parse(foo);
    console.log(foo);
    

提交回复
热议问题