2013-05-29 45 views
0

我是骨幹和dot.js的新手。我需要幫助將外部dot.js文件集成到我的主幹文件中。Backbone和dot.js

我的骨幹文件看起來像

success :function() { 

    SearchView = Backbone.View.extend({ 
     template: doT.template(dotView(id,fullurl)), 

     initialize: function() { 
      _.bindAll(this); 
      this.render(); 
     }, 

     render: function() {  
     this.$el.html(this.template({data: data.entries})); 
     }   
    }); 

    var search_view = new SearchView({ el: $("#search_container") });  

    } 

其中「dot.Template」我呼籲dotView這是目前在dot.js文件。這種方法工作正常,但我想用ajax來實現它。

我dot.js文件看起來像

function dotView(id,fullurl){ 
    temp = "{{~ it.data :value }}{{ if (check('{{=value.guid}}') == true) { }}<p>{{= value.title}}</p><p>{{= value.author}}</p><p>{{= value.description}}</p>"; 
    temp = temp + "{{~ it.data :value }}{{~ value.media$content :video}} {{ if (bitrate('{{= video.plfile$bitrate}}') == true) { }} {{ trigger_video(video.plfile$url); }} {{ } }} {{~}}{{~}}{{ } }}{{~}}"; 
    temp = temp + "<br/><div><b>See More:</b></div>{{~ it.data :value }}{{ if (check('{{=value.guid}}') != true) { }}{{~ value.media$thumbnails :photo}} {{ if (compare('{{=photo.plfile$width}}') == true) { }}<a href='details.html?id={{=value.guid}}&feed={{=fullurl}}'><img src='{{=photo.plfile$url}}' width='80' height='60'></img></a> {{ } }} {{~}} {{ } }}{{~}}"; 
    return temp; 
} 

在此

回答

0

RequireJS請幫忙推薦,它有一個!text插件。讓你將你的模板存儲在一個文本文件中。 requireJS會在你「需要」時異步加載它。