访问页面后不显示数据

问题描述:

您好我正在使用Durandal,knockout和renderjs构建一个SPA应用程序,我从一个页面转到另一个页面时似乎发现了一个问题。访问页面后不显示数据

这就是我目前的模式是这样的:

define(['services/logger', 'services/dataService', 'durandal/plugins/router'], 
function (logger, dataService, router) { 
    var allModulesObservableCollection = ko.observableArray(); 
    var isInitialized = false; 
    var activeSaIdParameter = ""; 

    var vm = { 
     //bindable 
     title: ko.observable(''), 
     dataLoading: ko.observable(false), 
     hasErrors: ko.observable(false), 
     errorMessage: ko.observable(''), 

     courseName: ko.observable(''), 
     allModules: allModulesObservableCollection, 

     //operations 
     refreshData: refreshData, 
     showActiveModules: showActiveModules, 
     activate: activate, 
    }; 

    return vm; 

    function activate(context) { 
     logger.log('All Modules View Activated', null, 'allModules', true); 
     if (!isInitialized) { 
      activeSaIdParameter = context.activeSaId; 
      isInitialized = true; 
      fetchModulesData(context.activeSaId); 
      return fetchHeaderData(context.activeSaId); 
     } else { 
      if (context.activeSaId != activeSaIdParameter) { 
       activeSaIdParameter = context.activeSaId; 
       fetchModulesData(context.activeSaId); 
       return fetchHeaderData(context.activeSaId); 
      } 
     } 
    } 


    function fetchModulesData(activeSaId) { 
     vm.dataLoading(true); 
     vm.hasErrors(false); 
     return dataService.getAllModulesInCourse(activeSaId) 
      .then(fetchModulesCompleted) 
      .fail(fetchDataFailed); 

     function fetchModulesCompleted(data) { 
      allModulesObservableCollection(data); 
      debugger; 
      vm.dataLoading(false); 
     } 
    } 

    function showActiveModules() { 
     var url = '#/activeModules/' + activeSaIdParameter; 
     router.navigateTo(url); 
    } 
}); 

第一次就得到的数据显示正确,一切要到另一个页面,然后试图回到这一个工程后fine.But,它就像浏览器完全忽略了JavaScript代码。

ShowActiveModules()负责让用户访问它的sibbling页面。

调试时我注意到在回到这个页面后,浏览器甚至不再运行这个代码。我必须完整地刷新页面以获取数据并显示它。

谁能告诉我我做错了什么?

+0

你能发布html视图吗? – 2013-04-23 17:25:46

由于RequireJS只读取一次文件,它不会再次运行此文件。

乍一看,你的'激活'功能应该再次被调用。你有没有试过在上放置一个断点,只是的“激活”功能?