2

marionette collectionView の使い方を知りたいです。定型文としてhttps://github.com/marionettejs/backbone.marionetteを使用しています。現在、コレクション ビューでレンダリングされたものは何も表示されません。

バックボーン コレクション

define(["jquery","backbone","models/Store"],
  function($, Backbone, Store) {
    // Creates a new Backbone Collection class object
    var StoreCollection = Backbone.Collection.extend({
      // Tells the Backbone Collection that all of it's models will be of type Model (listed up top as a dependency)
      model: Store
    });

    storeCollectionObj = new StoreCollection();
    storeCollectionObj.add({"title":"wherwr werwe"});
    return storeCollectionObj;
  });

モデル

define(["jquery", "backbone"],
    function($, Backbone) {
        // Creates a new Backbone Model class object
        var Store = Backbone.Model.extend({

            // Model Constructor
            initialize: function() {

            },

            // Default values for all of the Model attributes
            defaults: {

            },

            // Get's called automatically by Backbone when the set and/or save methods are called (Add your own logic)
            validate: function(attrs) {

            }

        });

        // Returns the Model class
        return Store;

    }

);

itemView

define( ['underscore', 'jquery', 'handlebars', 'text!templates/merchant/store.html'],
    function(_, $, Handlebars, template) {
        //ItemView provides some default rendering logic
        return Backbone.Marionette.ItemView.extend( {
            //Template HTML string
            template: Handlebars.compile(template), 
            id: "store",
            attributes: function () {
              return {class :"storeView"}
            },

            // View Event Handlers
            events: {

            }
        });
    });

コレクションビュー

define( ['underscore', 'jquery', 'handlebars' , 'views/merchant/StoreView','text!templates/merchant/storeCollection.html' , 'collections/StoreCollection'],
    function(_, $, Handlebars, SroreView, template, StoreCollection) {
        SroreViewObj = new SroreView();
        //storeCollectionObj = new StoreCollection();
        //alert(StoreCollection);
        //StoreCollection.add({"title":"sdfsadfasd"});
        //ItemView provides some default rendering logic
        StoreCollectionView = Backbone.Marionette.CollectionView.extend({
            id : "StoreListing",
            template: Handlebars.compile(template), 
            itemView: SroreViewObj,
            collection : StoreCollection,
            render: function(){

            }

        });

        return StoreCollectionView;
    });
4

1 に答える 1

0

私は自分の間違いを見つけました。コレクション ビューで itemView オブジェクトを渡していました。

itemView: SroreViewObjitemView: SroreView

「SroreViewObj」を「SroreView」(itemView定義)に置き換えるだけで修正

SroreViewObj = new SroreView();
        //storeCollectionObj = new StoreCollection();
        //alert(StoreCollection);
        //StoreCollection.add({"title":"sdfsadfasd"});
        //ItemView provides some default rendering logic
        StoreCollectionView = Backbone.Marionette.CollectionView.extend({
            id : "StoreListing",
            template: Handlebars.compile(template), 
            itemView: SroreViewObj, // This should not be an object. So fixed just by replacing "SroreViewObj" with "SroreView" (itemView definition)**
            collection : StoreCollection,
            render: function(){

            }

        });
于 2013-04-11T12:36:09.660 に答える