我有一个视图,其中许多控件(50+)都使用ng-model连接了一个范围控制器对象,但是我必须在将数据发布到api端点之前将库存对象的内容移动到另一个对象dataObj。我面临的问题是,当任何一个字段留空时,它不会与对象'库存'一起移动到控制器,因此当我在'inventory'和'dataObj'之间传输数据时,我得到了不确定,所以我做了一点检查如下所示在清单对象中收到的数据,但我不认为这是最好的方法,所以我希望有一些关于检查'库存'对象字段的最佳方法的建议,以确保它们是否存在在将它们移动到'dataObj'对象之前。感谢
表格(部分):
<div class="form-group">
<label>Price USD</label>
<input type="text" class="form-control" name="priceUSD" id="gps" placeholder="priceUSD" ng-model="inventory.prices.usd">
</div>
<div class="form-group">
<label>Price GBP</label>
<input type="text" class="form-control" name="priceGBP" id="priceGBP" placeholder="priceGBP" ng-model="inventory.prices.gbp">
</div>
JS
typeof inventory.prices.gbp === 'undefined'? dataObj.PRICES.gbp = '' : dataObj.PRICES.gbp = inventory.prices.gbp;