2015-10-16 153 views
0

我想呈现一个细节视图基于点击列表视图(父/子视图)。 所以我嵌套路线如下;灰烬渲染子模板

this.route('my-list', function() { 
    this.route('my-details', { 
     path: '/details' 
    }); 
}); 

而且我的孩子/详细路线看起来像下面

export default Ember.Route.extend({ 
model: function(params){ 
    var detailsUrl = "/myApp/json/" + params.myCode + "/details"; 
    var detailsRequest = new Ember.RSVP.Promise(function(resolve, reject) { 
     Ember.$.ajax({ 
      url: detailsUrl, 
      type: "POST", 
      data: JSON.stringify({ 
       'id': params.Id 
      }), 
      contentType: 'application/json;charset=utf-8', 
      dataType: 'json', 
      success: function(response) { 
       resolve(response); 
      }, 
      error: function(reason) { 
       reject(reason); 
      } 
     }); 
    }); 
    detailsRequest.then(function(response) { 
     return response; // I do get the correct response here 
    }, function(error) { 
    }); 
}, 
setupController: function(controller, model) { 
    debugger; 
    controller.set('model', model); 
} 
}); 

而且我的孩子/细节控制器看起来像下面

export default Ember.Controller.extend({ 
    queryParams: ['myCode','Id'], 
    productCode: null 
}); 

而且我的孩子模板如下; (我有一个{{口}}在我的父/列表模板)

<p>Child details </p> 
someId : {{model.someId}} 

虽然我能够使AJAX调用 “/对myApp/JSON /” + params.myCode + “/详细信息” 并得到响应,它没有得到渲染到子模板

我注意到setupController没有被调用。它有手动称为还是应该及早自动调用(做rememeber我使用的是嵌套视图)

+0

thx..but当你说之前detailsRequest – testndtv

回答

0

第一个错误,我看到的是,你的结果返回给承诺的功能不模型

export default Ember.Route.extend({ 

detailsRequest.then(function(response) { 
    return response; // I do get the correct response here 
}, function(error) { 
}); 

正确的方法应该是

return detailsRequest.then(function(response) { 
     return response; // I do get the correct response here 
    }, function(error) { 
+0

让我们来解决这个问题,然后继续前进,如果问题没有得到固定提供“reutrn”我无法理解清楚。 =) –

+0

Thx ..我现在看到setupController被调用并且模型被设置了正确的值......但是模板仍然没有更新......我需要做什么特别的渲染吗? – testndtv

+0

那么..真的不知道那是什么问题。发布您的ajax请求的结果以提问。 –