2013-08-04 94 views
0

我有一個使用John Papa的HotTowel的SPA項目。無法在HotTowel SPA上加載模塊

我在services文件夾listservice模塊和功能是這樣的:

define(['services/logger', 'models/businessobject', 'config'], 
    function (logger, businessobject, config) { 
     ... 
    } 

另外我有在models文件夾businessobject模塊。但是當我在listservice模塊中運行應用程序時,參數businessobject的值爲空。

有沒有什麼我想念告訴RequireJSDurandal/Amdbusinessobject模塊在那裏?

businessobject.js內容是這樣的:

define(['services/logger'], 
function(logger) { 
    var BusinessObject = function() { 
     var self = this; 
     self.id = ko.observable(); 
     self.typeId = ko.observable(); 
     self.descriptor = ko.observable(); 
     self.isNullo = false; 
     return self; 
    }; 

    return BusinessObject; 
} 

而且,使用螢火蟲,我已經簽了businessobject模塊被加載到客戶端。

回答

0

您的BusinessObject沒有以任何方式實例化。如果你想用它來揭露各種型號比你能做到這樣的 - 從你的listservice

define([], function() { 

    var businessModels = { 
     businessObject: businessObject 
    }; 
    return businessModels; 

    function businessObject(id, typeid, descriptor, isNullo) {  
     var self = this; 
     self.id = ko.observable(id); 
     self.typeId = ko.observable(typeid); 
     self.descriptor = ko.observable(descriptor); 
     self.isNullo = isnullo; 
    } 

然後

var myObj = new BusinessObject.businessObject(1, 2, 'my obj', false); 

或者,如果你只是想爲每個單個模塊模型,這看起來有點笨重,但肯定可以完成,你可以保留原來的代碼並正常實例化 -

var myObj = new BusinessObject();