Backbone收集在获取后触发未知错误

时间:2014-04-04 21:53:27

标签: jquery json rest backbone.js marionette

我已经意识到我一直在使用的技术发生了一些变化,但是,从现在开始,我突然无法使用正确提供的RESTful服务并使用正确的json解析。通过对主干集合的fetch的简单调用,错误不足以自行调试。因此,我希望有人能告诉我到目前为止发生了什么。

注意:在我的新应用程序版本之前,restful服务正常运行。

我有一个由Spring应用程序配置的restful服务,如下所述:

@Controller
@RequestMapping("/shop")
public class EstabelecimentoController {
     @Autowired
     private EstabelecimentoService estabelecimentoService;

    @RequestMapping(method = RequestMethod.GET)
    public @ResponseBody List<EstabelecimentoVo> getAll(@RequestParam( value = "type", required = false ) String type) {   
        List<EstabelecimentoVo> estabelecimentos = estabelecimentoService.findAllVo();          
        return estabelecimentos; 
    }

}

我的webapp使用主干,木偶,requirejs,jquery。这是我使用requirejs的配置:

require.config({

    baseUrl: 'lib',
    //path mappings for module names not found directly under baseUrl
    paths: {

        app:                    '../app/app',
        router:                 '../app/router',

        jquery:                 'jquery/jquery-2.0.2',
        jqueryui:               'jquery/jquery-ui-1.10.4.custom.min',       

        jqmconfig:              'jqm/jqm-config',
        jqm:                    'jqm/jquery.mobile-1.4.2.min',
        jqvalidator:            'jquery/jquery.validate.min', 
        jcookie:                'jquery/jquery.cookie',

        underscore:             'underscore/underscore',
        text:                   'require/text-2.0.10',

        backbone:               'backbone/backbone-1.1.2',
        marionette:             'backbone/marionette/backbone.marionette',
        wreqr :                 'backbone/marionette/backbone.wreqr',
        babysitter:             'backbone/marionette/backbone.babysitter',
        json2:                  'outras/json2',

        controllers:            '../app/controllers',
        models:                 '../app/models',
        collections:            '../app/collections',
        views:                  '../app/views',
        templates:              '../app/templates',
        session:                '../app/utils/session'

//          basic:          '../lib/api/default',

    },
    shim: {
        underscore: {
            exports: "_"
        },
        backbone: {
            //These script dependencies should be loaded before loading
            //backbone.js
            deps: ['jquery', 'jqm', 'jqueryui', 'underscore'],
            //Once loaded, use the global 'Backbone' as the
            //module value.
            exports: 'Backbone'
        },
        marionette: {
            deps: ['jquery','underscore','backbone','wreqr'],
            exports: 'Backbone.Marionette'
        },
        jqueryui: {
            exports: "$",
            deps: ['jquery']
        },
        jqmconfig: ['jquery'],
        jqm: ['jquery','jqmconfig']
    },
    config: {
        text: {
            useXhr: function (url, protocol, hostname, port) {
                // allow cross-domain requests
                // remote server allows CORS
                return true;
            }
        }
    }
});

这是我试图获取的收藏品

define(['jquery', 'underscore', 'backbone','models/shop/estabelecimento'],

        function ($, _, Backbone, Estabelecimento){
    'use strict';
    var EstabelecimentoCollection = Backbone.Collection.extend({

        // This is the model of the collection
        model: Estabelecimento,

        url : "http://192.168.0.100:8080/marketmobile/shop",
    });

    return EstabelecimentoCollection;
});

带有对方法的调用的ItemView:

define(['marionette',
        'models/shop/estabelecimento',
        'collections/estabelecimentoCollection',
        'text!templates/content/shop/listShop.html'],
        function(Marionette, 
             Shop,
             ShopCollection,
             listShopTemplate
        ){

    var ListShopView = Marionette.ItemView.extend({

        //initialize template
        template: _.template(listShopTemplate),

        getAll:function(){
            //set callback of the event "fetchCompleted:Books" 
            //this.collection.bind('fetchCompleted:Shops', this.render, this);
            var self = this;
            this.collection.fetch();
        },

        onRender: function(){
            this.trigger("renderCompleted:Shops",this);
        }

    });
    return ListShopView;
});

呼叫: / *  *控制器基本上只是一组对应的方法  *路由并由应用路由器调用。  * /

define([

        // Application.
        'app',
        // Misc.
        'session',

        'views/main',
        'views/estabelecimentos',
        'collections/estabelecimentoCollection'

        ], function(App, session, MainView, ListShopView, EstabelecimentoCollection) {
    'use strict';

    return {

        // The main page.
        index: function() {
            console.log('called index-controller');

        },

        // The list shop page.
        listShop: function() {
            console.log('called listshop-controller');
            var estabelecimentoListView = new ListShopView({collection: new EstabelecimentoCollection() });
            estabelecimentoListView.bind('renderCompleted:Shops', App.regionMain.show(estabelecimentoListView), this);
            estabelecimentoListView.getAll();
        }
    };

});

请求完成后,我从服务器得到200响应,但它仍然没有指向jquery-2.0.2.js的任何数据内容(第7858行)。

从浏览器返回:

GET http://192.168.0.100:8080/marketmobile/shop 200 OK 76ms

jquery-2.0.2.js(第7858行):

xhr.send( options.hasContent && options.data || null );

以前有人遇到过这个问题吗?提前谢谢大家

0 个答案:

没有答案