Forcing the view model to refresh view hiting the same module...

28 views
Skip to first unread message

Renison Christian

unread,
Dec 9, 2015, 2:00:38 PM12/9/15
to DurandalJS
define(['jquery', 'knockout','knockout.mapping','plugins/router'], function ($, ko, router) {
    function getJson(url) {
        return JSON.parse($.ajax({
            type: 'GET',
            url: url,
            dataType: 'json',
            global: false,
            async: false,
            success: function (data) {
                return data;
            }
        }).responseText);
    }

    var dv = ko.observable;
    var crnt = this.location.hash.split('/');
    console.log(crnt);
    if (crnt[2] == null) {
        dv = 5;
    }
    else {
        dv = crnt[2]
    }

    var myJsonObj = getJson('http://xxx.xxx.xxx.xxx:227/ddd.svc/getDVData/pop/' + dv);

    var menulist = getJson('http://xxx.xxx.xxx.xxx/ddd.svc/getMenus/pop');

    var parsedMenu = JSON.parse(menulist);

    var parsed = JSON.parse(myJsonObj);

    var arr = [];

    for (var x in parsed) {
        arr.push(parsed[x]);
    }

    var vm =
    {
        myObsArray: ko.observableArray(arr),
        menulist: parsedMenu,

        activate: function (context) {
            console.log(context);
            dv: context;
        },
        dv: dv
    };
    vm.cacheViews = false; 
    return vm;
   
});

This is my above code. I am trying to reload this whole vm based on any url change. I do see the url changing but dont see the view refreshed. I am very new to durandal and hoping to find some answers here in this group. I do get the url parameters in the activate but how can i force view to refresh?
Reply all
Reply to author
Forward
0 new messages