簡體   English   中英

如何在每個循環中使用underscore.js渲染TREE JSON?

[英]How to render is TREE JSON using underscore.js each loop?

我創建了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;
      }

下圖是我的收藏集。 在此處輸入圖片說明

我想知道如何訪問model.attributes(即如何訪問每個對象?)

我輸入的console.log語句類似於console.log(model.attributes.bathroom);

結果如下所示。 在此處輸入圖片說明

如何在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]);
       }
      }

    });

簡單地:

model.get('bathroom');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM