In javaScript How fix the result of eval() that has different result in IE7 and Edge?
var table = eval(tableId + "Table");
Related
My code is done in angular.js and I am trying to add several elements to the array. something like that:
$scope.my_array=[];
$scope.my_array.push({"element":1});
var data= {"element":2},{"element":3}
$scope.my_array.push(...data);
console.log($scope.my_array) => [{"element":1},{"element":2},{"element":3}]
I am developing in ionic, and in modern cell phones it works. but in cell phones with versions of 4.4 it does not work and this error appears.
"Uncaught SyntaxError: Unexpected token ."
What alternative can I do using good practice?
As mentioned in the comment by Barun, the ... spread syntax isn't supported. Use Array.concat to append the elements from data array to my_array array:
$scope.my_array=[];
$scope.my_array.push({"element":1});
var data= [{"element":2},{"element":3}];
$scope.my_array = $scope.my_array.concat(data);
console.log($scope.my_array);
For more information on JavaScript spread syntax:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax
I'm looking for a way to change the value (or format) for an individual series label when hovering it in anycharts.
Currently I'm only able to access the entire axis and I can find no getter method for individual labels so as to attach a listener.
xAxis.labels().listen('mouseOver', function(e) {
console.log(this, e.target);
});
This jsfiddle is as far as I got (see console log), this as well as the event.target reference the entire axis but not the label:
https://jsfiddle.net/robstarbuck/pbhd4b7L/9/
Indeed, there was a little bug with cache and format() function, our dev team made the fix, so please check the working sample:
var labelIndex = e.labelIndex;
var label = this.getLabel(labelIndex);
var value = xAxis.scale().ticks().get()[labelIndex];
label.format(value * 2);
https://jsfiddle.net/pbhd4b7L/13/ – it also shows how to work with tick values:
Currently it takes the js from branch, but this fix will be included in the upcoming release – 7.14.0 version (ETA: May 2017)
Our API is a little bit complicated here, but we're working hard to improve it. Does this what you're looking for?
var labelIndex = e.labelIndex;
var label = this.getLabel(labelIndex);
label.fontColor('red');
label.draw();
https://jsfiddle.net/pbhd4b7L/10/
This issue was fixed in the 7.14.0 release, use this code:
xAxis.labels().listen('mouseOver', function(e) {
var labelIndex = e.labelIndex;
var label = this.getLabel(labelIndex);
var value = xAxis.scale().ticks().get()[labelIndex];
label.format(value * 2);
label.fontColor('red');
label.draw();
});
with the latest version: https://jsfiddle.net/2t08ahkg/3/
I am working on geo location search in nodejs backend. And mongodb is the database. In order to do that, I am getting values from front end. I am using map getbound to get viewport data. Below are some variables that holds latitude and longitude.
var topLeftLong = parseFloat(req.body.topLeftLong);
var topLeftLat = parseFloat(req.body.topLeftLat);
var topRightLong = parseFloat(req.body.topRightLong);
var topRightLat = parseFloat(req.body.topRightLat);
var bottomRightLong = parseFloat(req.body.bottomRightLong);
var bottomRightLat = parseFloat(req.body.bottomRightLat);
var bottomLeftLong = parseFloat(req.body.bottomLeftLong);
var bottomLeftLat = parseFloat(req.body.bottomLeftLat);
Though I am getting these data, I want to put latitude and longitude in an array. But whenever I tried to push data in the array, I get the below error.
Seems like wrong data type is to blame. In your code if you applied cast, for e.g. (int)string-var, then it could be the error due to that. Data types are important. Mismatch data types would cause errors.
I am trying to merge two jsons into one but can't make it work. I manage to retrieve the data I need from both get, but I have troubles manipulating the jsons.
I planned on using two for loops but it doesn't work :
$scope.coursesJson = $http.get('https://api.myjson.com/bins/18zi3');
$scope.reviewsJson = $http.get('https://api.myjson.com/bins/52toz');
$q.all([$scope.coursesJson, $scope.reviewsJson]).then(function (values){
$scope.coursesJson = values[0];
$scope.reviewsJson = values[1];
for(i = 0;i<$scope.coursesJson.length;i++){
for(j = 0;j<$scope.reviewsJson.length;j++){
if($scope.coursesJson[i].name = $scope.reviewsJson[j].name){
$scope.coursesJson[i].reviews.push($scope.reviewsJson[j]);
}
}
}
console.log($scope.coursesJson);
});
Using the console, I can visualise the data but $scope.coursesJson.length is undefined and I don't understand why.
Maybe I don't understand $q well ?
EDIT :
Here is an example of the elements you could find in the coursesJson file I get() :
[{"code":"123 ","name":"Acteurs","courseContentGrade":null,"courseTeachingGrade":null,"courseAverage":null,"reviews":null},
{"code":"1234","name":"Advanced Excel","courseContentGrade":null,"courseTeachingGrade":null,"courseAverage":null,"reviews":null}]
And an example of the elements you could find in the reviewsJson file I get() :
[{"code":"123 ","name":"Acteurs","professor":"Lalala","contentReview":"C'est très réussi.","teachingReview":"charismatique","contentGrade":8,"teachingGrade":8,"average":8,"trimester":"T2","day":"Jeudi / Thursday","time":"9h-12h","round":"1er tour","bet":21,"year":"2014/2015","upvotes":"0","author":"Piranha","passed":null},
{"code":"123 ","name":"Acteurs","professor":"LAlalalala","contentReview":"Très intéressant !","teachingReview":"Disponible, claire.","contentGrade":8,"teachingGrade":8,"average":8,"trimester":"T2","day":"Jeudi / Thursday","time":"9h-12h","round":"1er tour","bet":25,"year":"2014/2015","upvotes":"0","author":"Piranha","passed":null}]
I would like to add the elements found in the reviewsJson to the reviews field of the elements of coursesJson. Could that be the problem ? I thought that using the push() method would create the array, but maybe I need to change all "reviews":null to "reviews":[] in coursesJson ?
I went to the url https://api.myjson.com/bins/ID1 and it's not an array, but an object. Instead of $scope.coursesJson.length I think you shouldbe doing $scope.coursesJson.tracks.length
I solved my issue really easyly and my question was actually pretty stupid.
What I tried to achieve didn't have its place on the front but on the backend.
I am using IronPython as a math parser with the DLR in my Silverlight project: it works, but computes incorrect results in cases involving division, as it uses integer instead of floating point math at times (so 4/3 returns 1). Google suggests adding from __future__ import division to the python script, but doing so throws an exception when I try to run it.
Are __future__ statements supported at all in IronPython? What can I do to make them work?
You'll have to make sure that __future__.py is available for import. I'm not sure how to do that for Silverlight, though.
Besides what Jeff suggested, you can also set the division behaviour when setting up the engine
var engineOptions = new Dictionary<string, object>();
engineOptions["DivisionOptions"] = PythonDivisionOptions.New;
var engine = Python.CreateEngine(engineOptions);
Console.WriteLine("{0}", engine.Execute("4 / 3"));
or when you compile your script:
var engine = Python.CreateEngine();
var compilerOptions = (PythonCompilerOptions)engine.GetCompilerOptions();
compilerOptions.Module |= ModuleOptions.TrueDivision;
var code = engine.CreateScriptSourceFromString("4 / 3").Compile(compilerOptions);
Console.WriteLine("{0}", code.Execute());