2013-12-20 127 views
0

我一直在閱讀this article和嵌套收集部分設置網址如下:骨幹嵌套集URL例如

'donut_shops /' + this.id + '/甜甜圈'

我想知道這將如何映射到web api控制器和操作等。即,donut_shops/5/donuts會在控制器上調用什麼?我可以理解,如果身份證是在最後,那麼會調用甜甜圈行動傳遞在身份證,但我很困惑與身份證在中間。

var DonutShop = Backbone.Model.extend({ 
    defaults : { 
    name : "Untitled" 
}, 

initialize : function() { 
// When you extend a Backbone.Model and give it an initialize function, 
// the function is called when you instantiate an instance of your Model. 

// The initialize function is used repeatedly in Backbone's prototypes. We'll be seeing this again 
this.donuts = new Donuts; 
this.donuts.url = 'donut_shops/' + this.id + "/donuts"; 
    } 
}); 

謝謝, 加里

回答

0

嵌套以這種方式訪問​​基礎資源的嵌入式集合。所以在這種情況下,有很多donut_shops,每個有很多。所以用這個網址:

'/donut_shops/5/donuts' 

GET所有的donut_shop的它有一個id的5

0

donuts_shops是商店

donuts_shops/5收集與ID店5

donuts_shops/5/donuts是一個集合,如果甜甜圈在商店與ID 5

donuts_shops/donuts所有甜甜圈收集所有商店

donuts_shops/5/donuts/6與ID店5

+0

感謝您的回答,並對遲到的回覆表示歉意,我明白將會返回哪些數據,即來自甜甜圈店5的甜甜圈等。但我不確定這將如何通過Web API調用實現。例如,我假設會有一個donut_shop控制器接受一個整數作爲它的id,這將返回donut_shop 5,但是Web API中的什麼方法將被調用來獲得這個shop甜甜圈?這全部是通過對Web API的一次調用完成的嗎? –

0

好吧,我想我已經找到了答案,我的問題在這個id爲6甜甜圈問題發佈前一陣子在計算器:

nested resources in ASP.net MVC 4 WebAPI

我想一半的技能是在知道你要搜索的內容:-)