javascript - DurandalJS - navigate without viewmodel refresh -


i have list of contact groups show on view. when click on contact group, want change current hash , load associated contacts.

say, have 3 contact groups

all (no id)

friends (id := 1)

family (id := 2)

others (id := 3)

if click on friends, url need change #/people/1 , callback needs called parameters (id = 1). if click on all, no id should passed (#/people) load contacts.

something like:

router.when("#/people/:id", function (routedata) {     console.log(routedata.id); //output: 1      // load contacts id });  router.when("#/people", function () {     // load contacts });  function oncontactgroupclick(contactgroup) {     router.navigatetowithoutreset("#/people/" + contactgroup.id); } 

the reason is, have central location not matter if call made via code or hand (change url, or click on hyperlink).

a example gmail/contacts

if use router.navigateto durandaljs, whole view model reloaded. there way durandaljs without refresh view model?

what mean central location?

from understand looking for:

define(["services/dataservice"], function (dataservice) {         var allcontacts = ko.observablearray();         var friendscontacts = ko.observablearray();         var contacts = ko.observablearray();         var loadedalldata= false;         var loadedfriends = false;         var vm = {             activate: activate,             contacts: contacts,         };         return vm;          function activate(routedata) {             var id = parseint(routedata.id);             if(id === 1)             {                if(loadedfriends)                {                   //push friends observable contacts                }                else                {                   //load friends server , set loadedfriends true.                }             }             else             {                if(loadedall)                {                    //push contacts contacts array                }                else                {                    //load webserver, , filter friends , put them friends observable. here set both loadedall , loadedfriends true.                }             }         }     } );  

so if binding view contacts when first time come screen looking friends url or hyperlink should load friends data web server, on subsequent comebacks same screen friends data should there not loaded again , again. durandal use same vm , not reset flags , observables (unless , until manually go , hit browser refresh button).


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -