Angularjs array changes reference after splice -
I am using Angels for my project and I'm working fine. I am facing a little different problem today, so I need some suggestions. Consider the code:
$ scope.deleteEmpty = function () {for (var sp = 0; sp & lt; $ scope.column.length; sp ++) {var offerings = $ scope.column [es]; If (offerings.spName == -1) {$ scope.removeanswer (sp); }}}, $ Scope.removeanswer = function (position) {for (var question = 1; question & lt; $ scope.rows.length; question ++) {$ scope.rows [question] .answerlst.splice , 1); }}, Here I am removing the answerlst according to Prasad's situation, it is being removed but there is a problem. Consider an example:
$ scope.column = [{spanname ':' - 1 ', spId:' 1 '}, {' spName ':' - 1 ', spId : '2'}, {'spName': '- 1', spId: '3'}, {'spName': '- 1', spId: '4'}] When to call for the first time, $ scope.removeanswer (sp); Delete the answer sequence for the first column, but after that the response of the answerlst is changed. Therefore it removes it for the first and the third place and not for the whole. Any suggestions please Thank you.
If there is more information then the following solutions can be improved.
This idea is to store the column index in a toRemove array and then delete all of them once from the answerlst . $ Scope.deleteEmpty = function () {var toRove = []; // extract for column index (var sp = 0; sp & lt; $ scope.column.length; sp ++) {var offerings = $ scope.column [sp]; If (offerings.spName == -1) {toRemove.push (sp); }} $ scope.removeanswer (toRemove); }, $ Scope.removeanswer = function (positions) {for (var question = 1; question & lt; $ scope.rows.length; question ++) {$ scope.rows [question] .answerlst = $ scope.rows [ Question]. .filter (function (value, index) {return status index of (index) <0};); }},
Comments
Post a Comment