2013-04-03 57 views
0

所有 我開發我的存儲目錄的多媒體應用程序,我已經收集JSON像這樣:+的NodeJS貓鼬+ Backbone.Marionette嵌套收集模板

{ "_id" : ObjectId("5142f55394474e2aac000001"), 
     "contentType" : "binary/octet-stream", 
     "length" : 2732376, 
     "chunkSize" : 262144, 
     "uploadDate" : Date(1363342677601), 
     "metadata" : { 
     "TIT2" : "Chase The Blues (Cameron McVey Remix)", 
     "TPE1" : "Terranova", 
     "TRCK" : "1/13", 
     "TALB" : "!K7", 
     "TPOS" : "1/1", 
     "TDRC" : "2000-06", 
     "TCON" : [ 
        "Electronica", 
        "Trip-Hop" ], 
     "COMM" : [ 
        "Chillout", 
        "Love", 
        "German", 
        "Berlin", 
        "2000s", 
        "Female Vocalists", 
        "Male Vocalists" ], 
     "TMED" : "CD", 
     "TMOO" : "Chill", 
     "TDOR" : "2000-06", 
     "TSO2" : "Various Artists", 
     "TPE2" : "Various Artists", 
     "TCMP" : "1", 
     "TSOP" : "Terranova", 
     "TIT1" : "Electronica", 
     "TPUB" : "Sinedín Music", 
     "TLAN" : "eng", 
     "TYER" : [ 
        "2000" ], 
     }, 
     "md5" : "617401af615ac0c6cb1dee9a3f1b99e6", 
     "origin" : "Chase The Blues.109eb5ab5105a1caa505a26657f7f9a8.mp3", 
     "evolution" : null, 
     "insertDate" : Date(1336662308000), 
     "tagSource" : "MusicBrainz", 
     "mediainfo" : 
        { "Format" : "MPEG Audio", 
        "Format version" : "Version 1", 
        "Format profile" : "Layer 3", 
        "Duration" : "3mn 47s", 
        "Bit rate mode" : "Constant", 
        "Bit rate" : "96.0 Kbps", 
        "Channel(s)" : "1 channel", 
        "Sampling rate" : "44.1 KHz", 
        "Compression mode" : "Lossy", 
        "Stream size" : "2.60 MiB (100%)", 
        "Language" : "English" 
        } 
     } 

所以,你可以看到,有在「元數據」,並在models.js「的MediaInfo」陣列文檔 中,在客戶端,我已經改寫這樣

​​3210

所以我創建兩個單獨收集模型解析功能'metadata'和'mediainfo' 我的問題是如何在html模板中呈現'metadata'和'mediainfo',因爲在'mediainfo'和'metadata'集合中,鍵值不固定,在'metadata'中某些鍵是數組項目在數組中的數量是不固定的

我創建backbone.marionette.itemview和CompositeView中的這兩個集合,但我不知道如何渲染

Plase,有人有一個解決方案? 問候

回答

0

最後我已經解決自己的問題與數據正常化,這是採用了新的架構貓鼬:

var TagSchema = new mongoose.Schema({ 
    value : {type : String, default: '', required: true} 
    }); 

    var MetadataSchema = new mongoose.Schema({ 
name : {type: String, default: '', required : true}, 
values: [TagSchema] 
    }); 

    var MediainfoSchema = new mongoose.Schema({ 
name : {type: String, default: ''}, 
value: {type: String, default: ''} 
    }); 

    var StreamSchema = new mongoose.Schema({ 
_id: mongoose.Schema.ObjectId, 
TIT2: {type : String, default: '', required: true}, 
metadata: [MetadataSchema], 
mediainfo:[MediainfoSchema] 
    }); 

使得具有的CollectionView和CompositeView中的序列我可以瀏覽整個模型 希望這可以幫助某人