2013-05-07 2 views
2

컬렉션 외부에있는 모델을 가져 오는 데 문제가 있습니다. 나는 많은 솔루션을 보았고 어떤 이유로 든 아무 것도 작동하지 않는 것 같습니다 (아마 어리석은 짓을하는 것 같습니다). 나는 실제로는 가져 오지 않는 실제 가져 오기에서 성공 함수를가집니다. 그것은 타격해야한다/장치/{의 DeviceID} 여기backbone.js가 단일 모델을 가져올 수 없습니다.

내 코드

define([ 
    'underscore', 
    'backbone', 


], function(_, Backbone) { 
    // Creating backbone model 
    var DeviceModel = Backbone.Model.extend({ 
    // set defaults 
    defaults: { 
    }, 

    idAttribute: "deviceId", 
    urlRoot: '/devices' 
    }) 
    return DeviceModel; 
}); 

내가

 model = new DeviceModel({deviceId: this.deviceId }) 

     model.fetch() 

에서 호출하고 당신을 감사합니다!

+1

model.fetch() 이후 브라우저 "네트워크"에서 쿼리를 보았습니까? –

+0

서버가'youserver.com/devices/deviceId'에서 모델을 제공합니까? – pfried

+0

@UlugbekKomilovich 아니요 –

답변

0

당신이 무슨 일이 일어나고 있는지 디버깅하는 콜백 함수를 전달하는 시도 할 수 : 그래서 BackboneJS Model-Fetch

Accepts success and error callbacks in the options hash, which are both passed (model, response, options) as arguments.

의 문서에서

model.fetch() 

, 당신은 포함 할 수

model.fetch({success: function(m, resp) { console.log(resp);}, 
       error: function(m, resp) { console.log(resp);} 
      }); 
관련 문제