How to get value from then in javascript - react-native

i have maybe stupid question.
I m trying to save XML file which i load through xml2js with readfile function.
I want to store file content string to global variable but i dont know how to get from promise then a value.
var myval;
var simpleStore = function(value){
myval = value;
}
var myvariable = RNFS.readFile(APPLICATION_HISTORY_DIRECTORY, 'utf8').then(simpleStore);

Related

Can I observe the change fo a variable in Kotlin?

I know I can use get a notification when the value of a variable has changed, Code A is OK.
I hope to monitor the change of a normal variable such as var myFilename="OK" in Code B, but myObserv isn't launching when myFilename has changed.
Can I observe the change fo a variable in Kotlin?
Code A
var savedFilename: String by Delegates.observable("") {
prop, old, new -> ...
}
Code B
var myFilename="OK"
var myObserv String by Delegates.observable(myFilename) {
prop, old, new -> ...
}

How to convert an object in vue back into a standard js object?

Is there a function to convert objects that have be converted into vuejs's reactive system back into a normal object?
I think you can try:
const normalObject = JSON.parse(JSON.stringify(objectWithReactivity)).
Even try a copy using ecmascript
object_reactive
let object = {...object_reactive}
or maybe just javascript
var obj = { a: 1 };
var copy = Object.assign({}, obj);

How to access 'this' tag instance inside tag lifecycle event?

I'm trying to update an array every time my tag receives an update from parent tags. Here is my code:
var tag = function(opts){
this.set = [];
var self = this;
this.on('updated', function(){
var obj = opts.my_topics;
var better_obj = {};
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
var topic_title = key;
better_obj = obj[key];
better_obj['title'] = key;
}
}
self.set.push(better_obj);
})
}
Whenever I try to push(), I get an error: Uncaught SyntaxError: Unexpected token ; database.js:60. The moment I remove the line of code for the push, the error disappears. Am I using this/self wrong in this case or could it be something else?
What I am trying to accomplish here is taking an object from opts (which receives regular updates), converting into an array, and using it for an each loop within my tag. I do not know how to do this other than a) what i'm trying to do now by accessing this, or b) rewiring my opts to deliver an array rather than an object (which is currently failing for me as I'm using Redux and it doesn't like dispatching non-objects).

Cannot get file name when upload file in google app script

I want to get file name when upload file finish. I have this example and follow this code.
However, when I get file name from following code:
var fileBlob = e.parameter.thefile;
The result is always return string "FileUpload".
How can I get the file name? Thank you so much.
You can get the name of the file by using the following code.
var fileBlob = e.parameter.thefile;
fileBlob.getName();
You can get the name of the file without storing in Drive through this.
Since fileBlob is of type blob we are getting through e.parameter.name, we have to refer Class Blob for that.
For further methods supported by Class Blob refer to
Class Blob.
The example script you were following produces a DocsList File object. This object has a method getName() so to extend the function in the example…
function doPost(e) {
// data returned is a blob for FileUpload widget
var fileBlob = e.parameter.thefile;
var doc = DocsList.createFile(fileBlob);
var fileName = doc.getName();
}
give that a whirl.

ASP.NET MVC 4 return Json resulting in double json or empty data

I am getting either empty Json results or double json results and I don't know why yet?
base line:
http://learn.knockoutjs.com/mail?folder=Inbox
looks like this in chrome F12: {"id":"Inbox","mails":[{"id":1,......}
My Action:
public ActionResult Mail()
{
string qs = "";
foreach (var q in Request.QueryString)
{
qs += string.Format("{0}={1}&", q, Request.QueryString[q.ToString()]);
}
var proxyRequest = "http://learn.knockoutjs.com/mail?" + qs;
var request = WebRequest.Create(proxyRequest);
var response = (HttpWebResponse)request.GetResponse();
var reader = new StreamReader(response.GetResponseStream());
var str = reader.ReadToEnd();
var data = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(str);
//var json = JsonConvert.SerializeObject(data);
// Text Visualization looks good {"id":"Inbox","mails":[{"id":1,"from":"Abb....}
// no outside quotes, no escaped quotes
var res = Json(data, JsonRequestBehavior.AllowGet);
return res;
}
So basically I am proxying the call, but the question is why is the result coming back as either not filled in or double jsoned.
using chrome network trace the result of the above looks like.
[[[]],[[[[[]],[[]],[[]],[[]],[[]],...]
valid json, just empty.
when I change the code to look like this
var json = JsonConvert.SerializeObject(data);
// Text Visualization looks good {"id":"Inbox","mails":[{"id":1,"from":"Abb....}
// no outside quotes, no escaped quotes
var res = Json(json, JsonRequestBehavior.AllowGet);
return res;
Chrome network trace has doubled jsoned the data.
"{\"id\":\"Inbox\",\"mails\":[{\"id\":1,\"from\":\"Ab....}"
Since I don't know what the Json actually is, I did newton soft dynamic convert
JsonConvert.DeserializeObject
That may be the problem behind my empty response?
Any help would really be appreciated.
Thanks
Your first method is failing because Json() doesn't understand the dynamic object returned from your JSON reader.
Your second method is failing because Json() is serializing a pre-serialized string.
You can return pre-serialized JSON data using Content(jsonString, "application/json")