javascript - Cannot Reach Deleted Array Object -


We are working on an app that will show a list of employees' shifts. If any change has already been passed, we want to remove it from the array of shifts and hence do not want to print it to the DOM.

We are effectively removing the object with the delete array by doing this, we know that by removing the object from undefined Will be left in the form. However, when it prints on the screen, it is undefined (this part is understood), but when we try to catch them with the function to fix this problem (we can arrange the array without any Copying), we '

HTML :

  & lt; Ul & gt; & Lt; Li ng- Repeatable = "Make changes to current user. Sort = (schedule | order: time.gettingdet: incorrect)" & gt; & Lt; P & gt; Start time: {{time.macad (change start)}} {{time.maketime (change start)}} & lt; / P & gt; & Lt; P & gt; End time: {{Time.makeDate (shift.end)}} {{Time.makeTime (shift.end)}} & lt; / P & gt; & Lt; / Li & gt; & Lt; / Ul & gt;  

UserController.js :

$ scope.getShifts = function () {$ scope.schedule = $ scope.CurrentUser .user.shifts; // array which is printed on the screen var now = new date (); (Var indexOfShift $ scope.schedule) {// Check each change var start = $ scope.schedule [indexOfShift]. Start; // Date object, start of shift if (for example starting date) {if (parseInt (start.getTime ()) - parseInt (now .gettime ()) <0} // if 'future time' Already have passed now // remove the shift alert (start + "is in the past"); $ Scope.CurrentUser.user.shifts [indexOfShift] delete; // shift $ scope.schedule = $ scope.CurrentUser Trying to update user.shifts; // that we have removed it, so for us undefined}}} (var indexOfShift $ scope.schedule) {// undef console.log ($ scope.schedule [ IndexOfShift]) to see again E; // it prints them all but do not appear ignored ($ scope.schedule [indexOfShift] .start === undefined) {// We never hit this warning ("An empty one And a sample of how our user data looks with shift (an array of objects):
  $ scope.CurrentUser.user = ['Name': 'John Smith', 'Change': [['Start': New Date (2012, 07, 27, 4, 44), 'End': New Date (2012, 07, 27, 12, 21)}, {'Start': New Date (2014, 09, 09, 20, 02), 'End': New Date (2014, 09, 10, 7, 06)}]}];  

Why can not we reach disasters? Where have they gone?

Use splice for your case.

The delete case in this case will essentially set the element:

myArray = ['a', 'b', 'c', 'd'] < / P>

remove myArray [0]

myArray

Result: [Undefined, "B", "C", "D"]

The marriage actually removes the element array:

myArray = ['a', 'b', 'c', 'd']

MyArray.splice (0, 2)

myArray

Result: ["C", "D"]

More About Splice For more:

For example from Missyila:

  var myFish = ["messenger", "joker", "drum", "manarine", "surgeon" ]; // removes deleted 1 element from index 3 = myFish.splice (3, 1); // myFish ["angel", "joker", "drum", "surgeon"] / / has been removed ["mandarin"]  

use it in your case.

Delete $ $ // scope.CurrentUser.user.shifts [indexOfShift]; $ Scope.CurrentUser.user.shifts.splice (indexfishf, 1);

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -