weixin_33724659 2014-03-19 00:03 采纳率: 0%
浏览 36

骨干获取不起作用

Following Backbone/Marionette Controller and Collection won't fetch.

define(["jquery", "backbone","models/Poi"],
    function($, Backbone, Poi) {
        // Creates a new Backbone Poi class object
        var PoiCollection = Backbone.Collection.extend({
            model:Poi,

            parse: function (response) {
                console.log(response);
                // Return people object which is the array from response
                return response;
            }
        });

        // Returns the Poi class
        return PoiCollection;
    }
);
define(['App', 'backbone', 'marionette', 'views/MapView', 'views/DesktopHeaderView', 'views/DesktopFooterView', 'models/Poi'],
        function (App, Backbone, Marionette, MapView, DesktopHeaderView, DesktopFooterView, Poi) {
            return Backbone.Marionette.Controller.extend({
                initialize: function (options) {
                    App.headerRegion.show(new DesktopHeaderView());
                    App.mainRegion.show(new MapView());
                    App.footerRegion.show(new DesktopFooterView());
                },
                //gets mapped to in AppRouter's appRoutes
                index: function () {

                    console.log("Ajax::list of POI");
                    var p = new Poi();
                    p.fetch({
                        success: function (data) {
                            console.log("data");
                        }
                    });
                    console.log(p);
                }
            });
        });

I have no Idea where to look to debug this. The Network tab tells me that the data was fetched, but the success method is never called.

Thanks

  • 写回答

1条回答 默认 最新

  • weixin_33736649 2014-03-19 01:02
    关注

    I think your fetch call itself looks OK, but two other apparent bugs could be affecting that call:

    1) Your log message in the index function says "list of Poi", but you're using a (single) Poi instance -- should that be PoiCollection instead? I'm assuming the Poi model (not shown above) is for a single item.

    2) There's no url property in the PoiCollection, so if you did fetch a PoiCollection instead, that call would fail because PoiCollection doesn't know what URL to use. The most common pattern with Collection + related Model is to put an url only in the Collection, and no url in the single Model for the Collection's individual items (Poi in this case). Backbone will construct the corresponding individual-model URLs as needed based on the parent Collection's url. I think getting the url straightened out will help here.

    Finally, one more thing: the fist parameter passed to the fetch call's success function is the Model or Collection instance itself, not the raw data object. That's not relevant for the current success code you have now (you're only logging a static string), but it will be relevant as soon as you try using that parameter. :-)

    评论

报告相同问题?

悬赏问题

  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码