0

At the console.log line in the render method below, it shows that this.member instance is exactly what it should be. So member object is good. I've spit out the string in tpl and it's what it should be. So what's causing the error in topic title?

Additional info: This view is a subview rendered by parent. I'm using Backbone.Subviews.

Thanks a lot for your help. I'm spinning my wheels :-/

Here is my code...

EDIT: Changed member object attrib references and now it works...

Template...

<div class="wrap-profile container">
    <div class="profile-pic">
        <div class="pic">
            <img src="<%= pathUploads %><%= member.photo_profile %>" width="400" height="600" id="<%= member.id %>" class="photo-img">
        </div>      
    </div>
    <div class="profile-info">
        <div>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent consectetur urna nec erat pretium tempus.
        </div>  
        <div>
            Morbi nec arcu at leo lobortis egestas. Phasellus sagittis neque dolor, ut congue lorem egestas id.m laoreet, vitae tristique lorem sollicitudin.
        </div>  
        <div>
            In vel libero eget enim rhoncus suscipit. Nunc tristique in nisi eget bibendum. Mauris et pulvinar orci.
        </div>  
        <div>
            Quisque eget sem id dolor tempus dictum. Pellentesque luctus scelerisque lacinia.
        </div>  
        <div>
            Sed gravida rutrum bibendum. Aenean condimentum eu dui nec adipiscing. Duis sagittis pharetra enim.
        </div>  
    </div>
</div>

The view js...

// ProfileView.js

define( function(require) {

    "use strict";

    var $                   = require('jquery'),
        _                   = require('underscore'), 
        Backbone            = require('backbone'), 
        Helper              = require('helper'), 
        tpl                 = require('text!templates/profilePicTemplate.html'),

        template            = _.template(tpl);

    return Backbone.View.extend({

        el: $("#profile"),

        initialize: function(member) {
            var self = this;
            this.member = member;
        },

        render: function() {
            var data = {
                pathUploads: Helper.global.pathUploads, 
                member: this.member 
            };
            console.log(this.member);
            this.$el.html(template(data));
            return this;
        },

        destroy: function() {
            template = null
            this.member = null;
        }

    });

});

Possible duplicate of Issue with an animated, sticky navigation in jQuery
Also, you could check some jQuery plugin wich does the job, for example http://stickyjs.com/

4

1 に答える 1

3

証拠は、サブクラスthis.memberのインスタンスではなく、単純な古い JavaScript オブジェクトであることを直接的に示しています。Backbone.Model意識されているようで、「いや、今聞いて後で信じろ」ということだと思います。この理論をテストするには、このスニペットを入れ替えます。

var data = {
  pathUploads: Helper.global.pathUploads, 
  member: new Backbone.Model(this.member) 
};

それで直れば理論は成り立つ。


(さておき…)

価値があるのは、プレーン データの代わりにバックボーン モデル インスタンスを必要とするテンプレートを作成することはおそらく劣っているため、<%= member.photo_profile %>代わりにテンプレートを使用することを検討して、データがどこから来ているかを気にしないようにすることです。これにより、プレゼンターのデザイン パターンも使いやすくなります。ビューで使用member.toJSON()して、プレーン データ属性を取得し、テンプレートに渡すことができます。

于 2013-08-15T22:09:36.360 に答える