Hi, I wonder how can I do this …
for example :
We suppose that this is my json file user.json…
module.exports = { “username”: "asd@gmail.com", “password”: “xx” }
This is ux file codes …
<JavaScript File="assets/user.json" ux:Global="MyJson" />
<JavaScript>
var username = Observable('');
var password = Observable('');
var user = Observable();
var MyJson = require("MyJson");
user.value = MyJson;
username.value=user.username; //I wonder this point exactly.
password.value=user.password;
</JavaScript>
but of course it doesn’t work. How can I do? Help me ,thanks.
Thx! It is really simple solution. I am suprised how I forgot to try it. Thank you for your help . And I want to ask one more thing. How can I do opposite ? So I want to convert some information to Json object that I take from user and write to user.json file.
If you want to have the defaults supplied by the Assets you first need to use the Storage API to see if a version has been saved. If it has load that file as JSON, if not use the defaults. To save a file just use the Storage API and save it the JSON as string like this: var jsonStr = JSON.stringify(user.value);
Thanks a lot for your answer. I investigated Storage topic and did a few exercises. I have a question.
<JavaScript File="Assets/de.json" ux:Global="aaa" />
function login(args){
addItem();
var storage = require('FuseJS/Storage');
storage.write("aaa",JSON.stringify(user.value));
storage.read("aaa").then(function(content) {
console.log(content);
console.log(content.uname); //it doesn't work.
}, function(error) {
console.log(error);
});
}
function addItem(args) {
user.add({ uname : username.value , passw : password.value });
}
How can I reach that Json object’s element I want to read. Also İf I add user more than one , how can I reach every one’s elements?