2

だから私は Backbone Marionette で遊んでいて、json データから collectionview を作成することができました。

これが私が持っているものの写真です

コレクションビュー

アンダースコアテンプレートを介してitemviewからデータを渡すネストされたビューを開くonclickイベントを各itemviewに持たせようとしています。これはスワップビューの例です(私のものではありません): http://jsfiddle.net/VLY4t/14/

これが私のコードの外観です(2番目の写真)(URLハッシュによるバックボーンルーターがありますが、アンダースコアテンプレートをレンダリングできないことに注意してください)。どんな助けでも大歓迎です.: 実際の例は次のようになります: 犬の品種は <%= name %> です Itemview の子

クライアント側のテンプレートと UI は次のとおりです。

<script type="text/template", id="dogs-template">
<ul><ul>
</script>

<script type="text/template", id="dog-template">
<a href="dogs/<%= name %>"> <%= name %>
</script>

<script type="text/template", id="play-template">
p This dog's breed is <%= name %>
</script>

Javascriptは次のとおりです。

//Im serving data via RESTful JSON, but the data looks like this
var dogs = [{name: 'yorkie'}, {name: 'pitbull'}, {name: 'dobberman'}, etc]

App = new Backbone.Marionette.Application();

App.addRegions({
mainRegion: "#content",
playRegion: "#play"
});

//Call the backbone history here

App.on("initialize:after", function(options){
  if (Backbone.history){
    Backbone.history.start({pushState: true});
  }
});


//Call the Controller


Controller = {


};

// Start the models n collections

Dog = Backbone.Model.extend({

});

Dogs = Backbone.Collection.extend({
model: Dog,
url: '/jonas',

});

DogView = Backbone.Marionette.ItemView.extend({
template: "#dog-template",
tagName: 'li',
initialize: function(){
        //var moot = _.bindAll(this.model);

    },



events: {
"click" : function() {
      //show new region here

      App.playRegion.show(theplayview);

    }
  }

});

PlayView = Backbone.Marionette.ItemView.extend({
template: '#play-template'

});

DogsView = Backbone.Marionette.CollectionView.extend({
template: "#dogs-template",
itemView: DogView
})

var doggies = new Dogs();
var bob = doggies.fetch({async: false});

var doggyview = new DogsView({collection: doggies});

App.mainRegion.show(doggyview);

var theplayview = new PlayView(this.model);


MyRouter = Backbone.Marionette.AppRouter.extend({
controller: Controller,


    appRoutes: {
        "": "route1",

        "testrouter": "route2",

        "testrouter#dogs": "route3",

        "testrouter#dogs/:id": "route4",


    },


});

App.addInitializer(function(){
console.log("Router is on")
new MyRouter();
});


App.on("initialize:after", function(){


}); 

App.start();
4

1 に答える 1