안녕하세요 저는 백본을 처음 사용하고 기본적으로 자바 스크립트를 HTML 페이지로 라우팅한다는 것을 이해하지만 application.html.erb
특정 URL이 없기 때문에 자바 스크립트를로 라우팅 할 수 없습니다 .
작업하려는 HTML을 제거하고 색인 페이지로 이동하여이 문제를 해결할 수 있지만 실제로 원하는 것은 아닙니다.
내 "솔루션"
views / posts / post_index.js.coffee
class Poster.Views.PostsIndex extends Backbone.View
template: JST['posts/index']
events:
'click #new_post': 'createPost'
initialize: ->
@collection.on('reset', @render, this)
@collection.on('add', @appendEntry, this)
render: ->
$(@el).html(@template())
@collection.each(@appendEntry)
this
createPost: (event) ->
Backbone.history.navigate("/posts/new", true)
appendEntry: (post) ->
view = new Poster.Views.Post(model: post)
$('#posts_container').append(view.render().el)
index.jst.eco
<div id="menu_bar" class="jumbotron menu_bar row">
<div class="col-sm-2">
<button id="new_post" type="button" class="btn btn-default">Post</button>
</div>
<div class="col-offset-8 col-sm-2">
List
</div>
</div>
프론트 엔드 프레임 워크를 사용하면 가장 좋은 방법은 js 액세스가 필요한 모든 것을 application.html 파일에서 제거하는 것입니다. 정말로 그 내용을 application.html 파일에 보관하고 싶다면 javascript로 쉽게 찾을 수 있도록 ID에 액세스하려는 각 요소를 부여 할 수 있습니다. 그 외에는 말한 것처럼 모든 것을 색인 페이지로 옮기는 것이 가장 좋습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다