Hi guys, i’m passing data from my home.js to a page using this code
function navigationdata(arg){
router.push("homechild", {data: arg.data})
}
everything works great but i would like to refresh these data in that page , so i imported the home.js in my page javascript like this
var home = require("home.js")
and added home.js to the unoproj file like this "home.js:Bundle". and tried to reload by calling home.loaddata() , the function run , but the data don’t refresh.
function laoddata(){
var publication = new Parse.Query("Publication")
geoLocation.getLocation().then(function(location){
publication.withinKilometers("location", new Parse.GeoPoint(location), 5000)
publication.notEqualTo("user", Parse.User.current())
publication.equalTo("status", "offres")
publication.include("user")
publication.descending("createdAt")
publication.find().then(function(results){
data.refreshAll(results,
function(oldItem, newItem){return oldItem.id == newItem.id; },
function(oldItem, newItem){newItem.time = newItem.get("createdAt");},
function(newItem){return new dataForm(newItem.id, newItem.get("nom"), newItem.get("description"), newItem.get("categories"), newItem.get("prix"), newItem.get("dates"), newItem.get("ville"), newItem.get("photo"), newItem.get("user"), newItem.get("createdAt"), newItem.get("location"), location, newItem);}
)
})
})
}
refreshing data only works when i call this function in the home page , but not on other pages
Generally, only bound Observable's will respond to updates. It is not clear from your code what is observable and not, and how this data is used whithin the homechild page, so hard to tell what’s wrong.
Hi anders , thank you for taking time to answer,
what do you mean with bound Observable? the purpose here is sample , for example if i have a settings page and profil page separated, i change my name and picture in the settings page and want the profil page to update (reload with a function) with those values set , how can i achieve that?
The general answer is: Keep an Observable somewhere (e.g. in a global module) with that information, write to that observable, data-bind that observable wherever you need the information.
You are not calling loadData more than once. When returning to your profilPage.ux you need to call loadData() one more time to load the up to date data. You can for example do:
please don’t hijack old threads, and post your own with complete, minimal reproductions.
In your global modules (Activity.js and Contact.js), you want to have a function that you can access from the outside:
var Observable = require("FuseJS/Observable");
var activityData = Observable();
function refresh() {
// do things, such as fetch()
}
module.exports = {
refresh: refresh,
activityData: activityData
};
Then in your viewmodels (Header.js), you want to include that global module you need, and call the function:
var Activity = require("Activity");
function refreshButton() {
Activity.refresh();
}
module.exports = {
refreshButton: refreshButton,
activityData: Activity.activityData
};