11

I have to arrays (Name and State Array) and map them togther into one object with the attrbiutes name and state.

Array Name:

 ["Time", "Riskchanged", "Scope", "Risk4", "Test", "Test(2)"]

Array State:

 ["In Bearbeitung", "Abgeschlossen", "In Bearbeitung", "Abgeschlossen", "Geplant", "In Bearbeitung"]

Function:

this.testArr = this.riskNamesArr.map( (x, i) => {
    return {"name": x, "state": this.riskWorkflowStateArr[i]}        
});

This works perfect on all Desktop Browsers but unfortunately not on my iOS Safari Browser.. The mobile Browser just shows nothing if I add those lines..

So is there another approach to get the same result?

2
  • Have you tried using the anonymous function in place of the Arrow function expression, does iOS Safari support ES6? Commented Jul 5, 2016 at 12:59
  • Like @simplesystems says, it would be a good idea to check the ES? compatibility here. Commented Jul 5, 2016 at 13:04

3 Answers 3

16

I think thats a problem with the arrow-function - thats ES6-style. Try using a simple function:

testArr = riskNamesArr.map( function(x, i){
    return {"name": x, "state": riskWorkflowStateArr[i]}        
}.bind(this));

JSFiddle: https://jsfiddle.net/urbr49d3/

Sign up to request clarification or add additional context in comments.

2 Comments

btw no need for bind, use thisArg. testArr = riskNamesArr.map( function(x, i){ return {"name": x, "state": riskWorkflowStateArr[i]} }, this);
@NinaScholz Thank you very much.
9

Safari for iOS does not yet support arrow functions () => {}. Use a normal function function() {} instead:

var riskWorkflowStateArr = this.riskWorkflowStateArr;
this.testArr = this.riskNamesArr.map(function(x, i) {
    return {"name": x, "state": riskWorkflowStateArr[i]}        
});

More about arrow functions.

Edit: Changed invalid this reference.

2 Comments

this results in a Uncaught TypeError: Cannot read property '0' of undefined
@simplesystems see my edit. In normal functions, the this reference does not necessarily point to the this reference of the surrounding block. In arrow functions, it does.
-3

Add this header on the server side responses to POST requests:

Cache-Control: no-cache

I suppose it's a cache problem, but not entirely sure. If it doesn't work. Please tell me and I will try to find another reason it's not working

1 Comment

This was a suggestion, a possible answer. I don't see why it should get a -1. The downvotes are related to the quality of the answer, not if it is the answer you were looking for or not.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.