【问题标题】:How to use marionette collectionView. I am using https://github.com/marionettejs/backbone.marionette as boilerplate如何使用木偶collectionView。我使用 https://github.com/marionettejs/backbone.marionette 作为样板
【发布时间】:2013-04-03 12:29:09
【问题描述】:

我想知道如何使用木偶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;

    }

);

项目视图

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: {

            }
        });
    });

CollectionView

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;
    });

【问题讨论】:

    标签: marionette


    【解决方案1】:

    我发现了我的错误。我在我的集​​合视图中传递了 itemView 对象。

    itemView: SroreViewObj 应该是itemView: 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(){
    
                }
    
            });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多