2014-10-09 63 views
0

的意外behavoiur此代碼工作定義requirejs

define([ 
    'jquery', 
    'underscore', 
    'backbone' 
], function($, _, Backbone,home_template) { 
    var HomeView = Backbone.View.extend({  
     render: function() { 
      alert('abcd'); 
     } 
    }); 

    return HomeView; 
}); 

這個代碼不工作

define([ 
    'jquery', 
    'underscore', 
    'backbone', 
    'text!modules/home/home_template.html' 
], 
function($, _, Backbone,home_template) { 
    var HomeView = Backbone.View.extend({  
     render: function() { 
      alert('abcd'); 
     } 
    }); 
    return HomeView; 
}); 

我的目錄結構是這樣的webroot /模塊/家用/ home_template.html

有什麼問題?

感謝

+0

在控制檯中的任何錯誤? – Evgeniy 2014-10-09 06:51:03

+0

@Evgeniy感謝您的評論。我得到這個錯誤「錯誤:腳本錯誤:文本http://requirejs.org/docs/errors.html#scripterror」 – Foysal 2014-10-09 07:21:30

+1

可以請你附上home_template.html的src? – Evgeniy 2014-10-09 07:23:31

回答

1

問題可能是兩種可能的地方:

1),路徑錯誤(U可以檢查在Firebug或在網絡選項卡中任何其他工具,尋找404錯誤)。它可能是模板或其他腳本放在客棧錯誤的文件夾。

2)模板語法錯誤 - 如果是下劃線,請確保您的模板包含在<script type="template">中。

相關問題