【问题标题】:Backbone-support nested view and Chrome骨干支持嵌套视图和 Chrome
【发布时间】:2013-08-14 18:19:13
【问题描述】:

这是我第一次使用骨干支持来处理僵尸视图。 在介绍之前,我没有遇到以下问题:

    this.$el.append(this.template());

    // this view fills up a select with options taken from a web services
    this.renderChildInto(new App.view.ResourcesView({name: "idActivityDesc", url: "/wfc-services/resources/activities"}), "#divIdActivityDesc");

    // population of the forms elements according to the loaded model
    this.populateSelectElements();
    this.populateTextElements();

    if(this.model.get('completed')) {
        this.$("#active").removeAttr("disabled");
    }

    this.delegateEvents(this.events);
    return this;

使用 Firefox 一切正常。如果模型为空,则将使用默认元素设置 select 元素。在我的例子中是 selectedIndex-1

在视图中进行调试一切似乎都很好。当视图将通过方法renderChildInto 发生在父级时,我遇到了问题。 dom 很好,但如果模型为空,则没有从 populateSelectElements() 派生的更改。如果它不是空的,我没有问题,并且视图工作正常。

我对此感到非常困惑,因为在 return this; 声明之前,即使在 Chrome/Chromium 中,我也会看到 selectedIndex-1。但在浏览器的最终渲染视图中,我看到选择具有 selectedIndex0

在composite_view.js中调用的代码是:

  renderChild: function(view) {
    view.render();
    this.children.push(view);
    view.parent = this;
  },

  renderChildInto: function(view, container) {
    this.renderChild(view);
    this.$(container).html(view.el);
  },

【问题讨论】:

    标签: google-chrome backbone.js chromium


    【解决方案1】:

    故事到此结束。

    我从包括 stackoverflow 在内的许多来源中发现,可以使用 selectedIndex 到 -1。

    我不是前端开发人员,我在浏览器兼容性方面没有太多经验,所以我从我的一位专家那里找到了我需要的帮助,并且基本上建议我使用 selectedIndex 的这种类型真的很奇怪。

    他建议我使用值为“-”或任何符合域的默认选项元素来定义一个空元素。

    工作就像一个魅力,因为我们实际上在设计中做得很好,我们只需将 selectedIndex 从 -1 更改为 0。

    【讨论】:

      猜你喜欢
      • 2013-05-14
      • 2013-01-14
      • 2013-10-25
      • 1970-01-01
      • 2015-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-10
      相关资源
      最近更新 更多