在Backbone.Marionette Web应用程序中,我将 View 资源从一个 View 复制到另一个 View ,并且在加载Web应用程序时遇到了意外的 token 错误。 View 定义就像您在下面看到的一样,我只是将其中一个 View 定义从该页面移至另一个定义页面(Marionette.Layout)

define([
  'app',
  'lib/underscore',
  'lib/backbone',
  'lib/backbone.marionette',
  'lib/Backbone.ModalDialog',
  'lib/alertify',
  'text!modules/header/templates/mytemplate.html',
  'modules/header/views/another',
  'modules/header/views/andanother'],
function(App, _, Backbone, Marionette, btm, alertify, template, AnotherView, AndAnotherView) {
  var MyView = Marionette.CompositeView.extend({
   ...

以前,我将这种类型的错误归结为错误的路由。解决路线可以解决问题,但这里似乎不是问题。出现该错误是因为该框架试图将JSON呈现到模板中,但获取的是html格式的错误消息而不是数据。

该通知来自全局错误处理程序中的alertify;您在处理程序中没有得到堆栈跟踪,请参见以下讨论:
When will proper stack traces be provided on window.onError function?

我可以逐步解决该错误(深入了解框架回调),但是一切都很好,直到引发错误为止,即使是将要呈现的内容也是如此。

最佳答案

当我看到“意外的 token

09-11 00:40
查看更多