导出并使用骨干模型并查看抛出错误

时间:2013-02-05 12:21:29

标签: backbone.js requirejs

我在我的应用中使用'require.js',我收到此错误:

ReferenceError: Can't find variable: appModel
require.js:32Error: Load timeout for modules: listView

我无法理解我的方面有什么问题:

我的配置是:

requirejs.config({
    baseUrl:"scripts",
    paths:{
        //libraries
        jquery          :"lib/jquery-1.9.0.min",
        jqueryUI        :"lib/jquery-ui-1.9.2.custom.min",
        underScore      :"lib/lodash-1.0.0.min",
        backBone        :"lib/backbone-min",
        //scripts
        appInit         :"js/tasklist",
        loginValidate   :"js/loginValidate",
        listModel       :"js/models/listModel",
        listCollection  :"js/collections/listCollection",
        listView        :"js/views/listView"
    },
    shim:{
        "underScore":{
            exports: "_"
        },
        "backBone":{
            exports:"Backbone",
            deps:["underScore"]
        },
        "appInit" : {
            deps:["jquery","jqueryUI","underScore","backBone"]
        },
        "jqueryUI":{
            deps:["jquery"]
        },
        "loginValidate":{
            deps:['jquery']
        },
        "listModel":{
            exports:"listModel",
            deps:["backBone"]
        },
        "listCollection":{
            exports:"listCollection",
            deps:["listModel"]
        },
        "listView":{
            exports:"listView",
            deps:["listModel","listCollection"]
        }
    }
});

require(['jquery'],function(){
    if($('#tlLoginForm').length){
        require(["jquery","loginValidate"],function($){
            $(function(){
                var paramsLoginForm = {
                        loginForm : $('#tlLoginForm')
                    };
                var validate = tasklistHandler(paramsLoginForm);
                validate.init(); //it works fine.
            });
        });
    }
    if($("#boardTemplate").length){ // i am finding my template and initiating the values
        require(["backBone","listModel","listCollection","listView"], function(){

        });
    };
});

listModel.js中的模型

require(['jquery','backBone'],function($,Backbone){ // i am importing jquery, and backbone and assigning the model
var appModel = Backbone.Model.extend({
        url : 'data/data.json',
        defaults:{
          "id"                  :"id",
          "title"               :"Title",
          "projectName"         :"project",
          "dueDays"             :0,
          "dueTime"             :0,
          "dueDate"             :"0-0-0000",
          "totalTasks"          :0,
          "taskCompleted"       :0,
          "percent"             :65,
          "taskStatus"          :"Assigned",
          "jobtype"             :"vip",
          "username"            :"scott.pierce@groupfmg.com",
          "notes"               :"notes1"
        }  
      });

      return appModel; // tried not works
});

我在listCollection.js中的集合

define(["jquery","backBone","listModel"],function($,Backbone,model){ 

//我正在导入在listModel.js中声明的jquery,backbone和model,但它不是 工作! 的console.log( '集合',模型); //我的模型未定义         var collection = Backbone.Collection.extend({             型号:型号,             初始化:功能(){                 的console.log(this.model);             }         });

    var newModel = new appModel; //ReferenceError: Can't find variable: appModel
    console.log(newModel); // throw the error as like i mentioned.
});

任何人都可以帮我纠正我的问题吗?

1 个答案:

答案 0 :(得分:0)

这对我有用..

而不是使用"require"我使用"define"。这一切都很好。

谢谢大家。