小编djm*_*ick的帖子

Underscore.js _.template导致Chrome扩展程序出错

如果我在Google Chrome扩展程序中使用underscore.js_.template(),我会在控制台中收到以下错误:

未捕获的错误:对于此上下文不允许从字符串生成代码

有没有办法克服这个错误?

javascript google-chrome-extension underscore.js

17
推荐指数
2
解决办法
6315
查看次数

骨干模型未定义?

我无法理解为什么this.model会在view.intialize()中定义,当我在它上面运行this.model.fetch()而不是在view.render()中.

Chrome开发者工具截图

define([
  'jquery',
  'underscore',
  'backbone',
  'text!templates/example.html'
], function($, _, Backbone, exampleTemplate){

  var exampleView = Backbone.View.extend({
    el: $('body'),
    initialize: function() {
      this.model.set({ _id: this.options.user_id });
      this.model.fetch({
        success: this.render,
        error: function(model, response) {
          console.log('ERROR FETCHING MODEL');
          console.log(model);
          console.log(response);
        }
      });
    },
    render: function() {
      console.log('HELLO FROM RENDER');
      console.log(this.model);
      console.log('GOODBYE FROM RENDER');
    }
  });

  return exampleView;

});
Run Code Online (Sandbox Code Playgroud)

javascript backbone.js

5
推荐指数
1
解决办法
5080
查看次数