1
나는 간단한 백본 응용 프로그램을 만들었습니다. 이제 문제가 생겨서 문제가 해결되어야합니다. 그래서 나는 조언을 구한다.백본 사용자 그룹을 기반으로 한보기 읽기/편집
사용자/그룹 단위로 내 모델/컬렉션을 읽기 전용 또는 편집 가능으로 나타내야합니다.
초기 생각은 두 개의 템플릿 (읽기 및 수정)과 각각의보기를 만드는 것입니다. (사이비 코드) :
var appRouter = Backbone.Router.extend({
routes: {
'' : 'schedule',
}
schedule: function() {
this.collection = new Collection();
this.collection.fetch({success:function(resp) {
if (resp.group == 'allowedToEdit')
myview = new editView(this.collection);
else
myview = new readView(this.collection);
}});
});
이 방법은 나 템플릿을 복제 할 필요와 바람 :
<script type="text/template" id="edit-template">
<div class="myclass">
<input class="fn" type="text" value="<%= (fn) != '' ? fn : 'default' %>">
</div>
</script>
<script type="text/template" id="static-template">
<div class="myclass">
<div class="fn"><%= fn %></div>
</div>
</script>
그것이 더 나은겠습니까 인라인 자바 스크립트 대신 또는 아마도
input
또는
div
태그를 선택 내가 생각하지 못한 더 나은 해결책이 있습니까?
내가 사용자 환경 설정을 사용자가 편집 할 수 또는되지 않은 경우 (사용자 권한에 따라 데이터베이스에서 반환) 부울 값을 포함하는 사용자 모델을 만들어 : 이것은 내가하고 결국 무엇