English 中文(简体)
铁道语法错误,未经承认的表达式: 1
原标题:BackboneJS on Rails Syntax Error, unrecognized expression: /1

我试图为通过链接访问的《邮报》设置一个显示页:

<a class="post-link button" href="#">details</a>

当邮寄项目完成时, 给它一个像这样的href :

this.$( a ).attr( href , this.postUrl());

...

postUrl: function() {
  return "#posts/" + this.model.get( id );
}

当字段完成时,链接显示为:

http://[path_to_app]/#posts/[whatever_id]

当我点击链接时, 它的 应该 击中这个路由器 :

routes: {
              :  index ,
   new        :  newPost ,
  "posts/:id" :  show 
}

但我得到这个错误, 它从来没有进入到显示函数 在所有的:

Uncaught Error: Syntax error, unrecognized expression: /1 jquery.js:4268
  Sizzle.errorjquery.js:4268
  Sizzle.filterjquery.js:4254
  Sizzlejquery.js:4044
  Sizzlejquery.js:5176
  jQuery.fn.extend.findjquery.js:5432
  jQuery.fn.jQuery.initjquery.js:188
  jQueryjquery.js:28
  hashchangetabs.js:9
  jQuery.event.dispatchjquery.js:3333
  jQuery.event.add.elemData.handle.eventHandle

当我将链接改为“#post/” + id ” 和“post/: id” 路径时,这个错误就不会发生。

我正在学习 Backbone, 并在此真的需要一只手。 还有一点值得注意:我的路径根到#index 行动 。

EDIT(更相关的代码):

# Model
[APP].Models.Post = Backbone.Model.extend({
  urlRoot:  /posts 
});

#Router
[APP].Routers.Posts = Support.SwappingRouter.extend({
  initialize: function(options) {
    this.el = $( #posts );
    this.collection = options.collection;
  },

  routes: {
                :  index ,
     new        :  newPost ,
    "posts/:id" :  show 
  },

  index: function() {
    var view = new [APP].Views.PostsIndex({ collection: this.collection });
    this.swap(view);
  },

  newPost: function() {
    var view = new [APP].Views.PostsNew({ collection: this.collection });
    this.swap(view);
  },

  show: function(postId) {
    var post = this.collection.get(postId);
    var postsRouter = this;
    post.fetch({
      success: function() {
        var view = new [APP].Views.PostShow({ model: post });
        postsRouter.swap(view);
      }
    });
  }
});

#Post Item View
[APP].Views.PostItem = Backbone.View.extend({
  tagName:  tr ,

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

  render: function () {
    this.$el.attr( id ,  post_  + this.model.id);
    this.$el.html(JST[ posts/item ]({ post: this.model }));
    this.renderFormContents();
    return this;
  },

  renderFormContents: function() {
    ...
    this.$( a ).attr( href , this.postUrl());
  },

  postUrl: function() {
    return "#posts/" + this.model.get( id );
  }
});
最佳回答

有些地方,不知何故,这个问题是由没有按一定顺序装入文件造成的。我希望我能说得更具体些,但我并没有在正确的地方装上主干线.min.js。

不过,我有一些功能, 因为我已经包括一个老骨干部分文件, 我试图定制,打破, 认为被删除了。

真的,非常愚蠢的错误,我一阵子都搞不懂,谢谢你的帮助

问题回答

在 Backbone 文档上检查 url 和 urlRooot : 您可能不需要手动设置标准休息资源 : < a href="http://documentcloud.github. com/backbone/#Model- url" rel= "nofollow" >http://documentcloud.github.com/backbone/# Model-url





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签