js代码
var dataObj = {}; var shipDataObj = []; function shipData(shipDataObj){ for(i=0;i<shipDataObj.length;i++){ dataObj.push({ addressLine1 : shipDataObj[i].addressLine1, addressLine2 : shipDataObj[i].addressLine2, city : shipDataObj[i].city, state : shipDataObj[i].state, country : shipDataObj[i].country, zip : shipDataObj[i].zipCode, contactNum : shipDataObj[i].contactNumber }); } } appServices.getAddress(userData.customerId).then(function (data){ if (data){ console.log(data); $scope.shipDataObj = data; shipData(data); console.log(dataObj); } });我只需要data.I中的7个属性。我在shipDataObj中复制了数据对象并调用了一个名为shipData的函数。 shipData将推送shipDataObj中的属性。 shipDataObj可能有两个索引,如0和1,每个索引都有7个属性。这7个属性我必须在dataObj中推送,这样我才能只显示这些属性。
我不明白为什么这个错误即将到来dataObj不是一个函数。
js code
var dataObj = {}; var shipDataObj = []; function shipData(shipDataObj){ for(i=0;i<shipDataObj.length;i++){ dataObj.push({ addressLine1 : shipDataObj[i].addressLine1, addressLine2 : shipDataObj[i].addressLine2, city : shipDataObj[i].city, state : shipDataObj[i].state, country : shipDataObj[i].country, zip : shipDataObj[i].zipCode, contactNum : shipDataObj[i].contactNumber }); } } appServices.getAddress(userData.customerId).then(function (data){ if (data){ console.log(data); $scope.shipDataObj = data; shipData(data); console.log(dataObj); } });I need only 7 properties from data.I copied data object in shipDataObj and called a function named shipData. shipData will push the properties in shipDataObj. shipDataObj may have two indexes like 0 and 1 each of them have those 7 properties.these 7 properties I have to push in dataObj so that I can display only these properties.
I dont understand why this error is coming dataObj is not a function.
最满意答案
dataObj变量的值是对象引用,对象没有.push()方法。 如果你真的希望它是一个数组,它的初始化应该是这样的
var dataObj = [];The value of your dataObj variable is an object reference, and objects don't have a .push() method. If you really want it to be an array, its initialization should look like
var dataObj = [];更多推荐
发布评论