javascript - 如何使用 underscore.js 每个循环渲染 TREE JSON?

标签 javascript json backbone.js underscore.js underscore.js-templating

我创建了 JSON TREE 的集合插入类型。

view.js

views.Livingword = Backbone.View.extend({
      render: function(templateName) {
        var template = _.template(templateName);
        this.$el.html(template({result : this.collection.models}));
        _.each(this.collection.models, function(model){
          console.log(model.attributes.bathroom);
        });
        return this;
      }

我的收藏已设置,如下图所示。 enter image description here

我想知道如何访问 model.attributes (即如何访问每个对象?)

我输入了 console.log 语句,类似于 console.log(model.attributes.bathroom);

结果如下所示。 enter image description here

如何在 html 中使用 underscore.js each 访问此属性?
我真的想要它的解决方案。

<小时/>

最佳答案

试试这个,也许这就是你想要的

_.each(this.collection.models, function(model){
      console.log(model.attributes.bathroom); 
      for(var i in model.attributes){
       if (model.attributes.hasOwnProperty(i)){
        console.log(model.attributes[i]);
       }
      }

    });

关于javascript - 如何使用 underscore.js 每个循环渲染 TREE JSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42649494/

相关文章:

javascript - 如何在 Angular 中为多选选择标签设置多个默认值

javascript - AUDIO 和 pitch 上的 playbackRate

javascript - react + Redux : Invariant Violation: Could not find "store" in either the context or props of "Connect(Body)"

javascript - 自定义 Backbone.Model 操作不起作用

javascript - 是否有任何 Backbone.js 教程教 ".sync"与服务器?

javascript - 而不是 $.each 想使用 Array.find

python - 有没有办法将 json 压缩成 web2py 中的行和列?

PHP 数组转换为 Json 并将数据恢复到网页中

来自谷歌电子表格的 JSON 数据

jquery - 在 Backbone View 的事件哈希中使用自定义 jquery 插件