English 中文(简体)
备用:如何重新使用在装页时表达的观点
原标题:Backbone: how to reuse a view rendered during page load

我正在设立一个管理员,用户可以预订其喜欢的网页URLs,然后在文件夹中管理。

  1. During app load, I render a view which shows the list of folders user has created. this view is invisible on page load.
  2. then user navigates to his home page to see a list of urls
  3. from there, user can arrange the urls in folders
  4. user clicks the Move to folder icon in URL view
  5. I want to display the folderSelectorView absolute positioned below the Move to Folder icon. How can I do that?
  6. Also if the url has already been moved to a folder, I want a checked sign to appear in the folderSelectorView in the folder where the url has been moved to.

我应怎样做呢?

这里是我如何把文件夹在上面。

var folderColl = new FolderColl();
new FolderSelectorView({collection: folderColl});

The Code for URL view.

URLView = Backbone.View.extend({
    tagName:  li ,
    template: _.template($( #URLTempalte ).html()),
    events: {
         click .FolderChange :  showFolderSelector 
    },

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

    render: function() {
        return $(this.el).html(this.template(this.model.toJSON()));
    },

    showFolderSelector: function() {
       // How should I display the view here
       // view should display below the "Move to folder" icon
       // Doing something like `new FolderSelectorView` is not what I m after
       // since that will just re-render the view for every URL displayed
    }
});
最佳回答

你可以轻而易举地对现有的超文本部分寄以主意。 你们需要做的是通过<代码>el,以供查阅。 <el>可以是你想要的东西,包括通过j Query 挑选人发现的现有html要素。

var myEl = $("#someElementOnThePage");
var myView = new MyView({
  el: myEl
});

This will attach your view to the #someElementOnThePage element, and you can then use it as if you had rendered it yourself.

更多例子见我的博客关于逐步拟订的内容:

问题回答

暂无回答




相关问题
What s the appropriate granularity for Backbone.js Views?

I m adopting Backbone.js to render a small corner of an existing large web app. If this goes well, I can see Backbone.js growing to encompass the whole of the app, lending some much-needed structure ...

Rendering Layouts with Backbone.js

If you were to build a single page web application (SPWA) using Backbone.js and jQuery with--for example--two controllers that each required a unique page layouts, how would you render the layout? ...

Load html without refresh

Im unsure of how to approach this, should I have the html to be loaded hidden or load it from somewhere? I want to load a form in one page, and dynamic content on other pages. The form can be saved ...

Why are my CoffeeScript/backbone.js events not firing?

I m trying to familiarize myself with CoffeeScript and backbone.js, and I must be missing something. This CoffeeScript: MyView = Backbone.View.extend events: { "click" : "testHandler" ...

热门标签