Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Spine.js未知记录(可能的范围错误?)_Javascript_Spine.js - Fatal编程技术网

Javascript Spine.js未知记录(可能的范围错误?)

Javascript Spine.js未知记录(可能的范围错误?),javascript,spine.js,Javascript,Spine.js,如果我有一个相册列表,并单击其中一个,我将导航到另一个视图//album/:id,该视图由名为SingleAlbum的控制器控制。它正确地获取了数据,但我无法将其渲染。我在谷歌集团的Spine上查看了其他一些“未知记录”的问题,但没有发现。这是我的密码: var SingleAlbum = Spine.Controller.sub({ apiObj: { url: '/api/album', processData: true, data:

如果我有一个相册列表,并单击其中一个,我将导航到另一个视图//album/:id,该视图由名为SingleAlbum的控制器控制。它正确地获取了数据,但我无法将其渲染。我在谷歌集团的Spine上查看了其他一些“未知记录”的问题,但没有发现。这是我的密码:

var SingleAlbum = Spine.Controller.sub({
    apiObj: {
        url: '/api/album',
        processData: true,
        data: {
            id: ''
        }
    },
    model: Album,
    panel: $('.album_single'),
    tmpl: $('#albumTpl'),

    init: function() {
        this.apiObj.url = this.model.url;
        if(this.panel.children.length > 0) {
            this.panel.html('');
        }
    },
    render: function(id) {
        console.log('render');

        var template = singleAlbum.tmpl.html(),
            data = Album.find(id), //  <--  this doesn't want to work
            html = Mustache.to_html(template, data);
        singleAlbum.panel.html(html);
    },
    getData: function(id) {
        //var me = this;
        console.log('get data');
        this.apiObj.data.id = id;
        this.apiObj.url = this.model.url;

        this.model.bind('refresh change', function(id) {
            //me.render(id);
            singleAlbum.render(id);
            console.log('should be rendered');
        });

        this.model.fetch(this.apiObj);
        console.log('record: ',this.model.find(id));
        if(Object.keys(this.model.find(id)).length > 0) {
            //this.render(id);
        }
    }   

});
啊哈!我在事件处理程序中传递id,这将覆盖另一个id变量。下面是它的外观:

render: function(id) {
        var template = this.tmpl.html(),
            data = this.model.find(id),
            html = Mustache.to_html(template, data);
        this.panel.html(html);
},
getData: function(id) {
        var me = this;
        this.apiObj.data.id = id;
        this.apiObj.url = this.model.url;

        this.model.bind('refresh change', function() {  //  <--  don't need to pass anything
            me.render(id);
        });

        this.model.fetch(this.apiObj);
}
render: function(id) {
        var template = this.tmpl.html(),
            data = this.model.find(id),
            html = Mustache.to_html(template, data);
        this.panel.html(html);
},
getData: function(id) {
        var me = this;
        this.apiObj.data.id = id;
        this.apiObj.url = this.model.url;

        this.model.bind('refresh change', function() {  //  <--  don't need to pass anything
            me.render(id);
        });

        this.model.fetch(this.apiObj);
}