2014-05-04 112 views
0

下面是我的收藏中的一個模型,我如何從集合中提取它 - 通過id找到它?骨幹從ID獲取模型

我通常做:

var twitter_id = window.localStorage.getItem("twitter_id"); 
AttoriBackEnd.twitter.fetch({nome:nomecercato,type:'twitter'}); 
AttoreTwitter= AttoriBackEnd.twitter.get(twitter_id); 

但現在不提取任何東西(我使用的骨幹1.1.2,另一個版本,它完美地工作)。

models: Array[4] 
0: child 
_changing: false 
_events: Object 
_pending: false 
_previousAttributes: Object 
attributes: Object 
changed: Object 
cid: "c50" 
collection: child 
id: "8696369" 

回答

0

只是簡單地使用內置的方法收集(findWhere)

返回匹配從收集

AttoreTwitter = AttoriBackEnd.twitter.findWhere({ 
    // If model's id is twitter_id then 
    id: twitter_id 
    // else if model's twitter_id is set on model itself then 
    twitter_id: twitter_id 
}); 

好運twitter_id是單一的模式

+0

不工作!我無法理解...... –

+0

你能告訴我該模型的數據維度 – Samuraik

0

根據我所看到的,我覺得像你需要等待直到fetch完成,那麼你可以得到集合中的某個模型。下面是做這件事:

var twitter_id = window.localStorage.getItem("twitter_id"); 
AttoriBackEnd.twitter.fetch({nome:nomecercato,type:'twitter'}); 

var AttoreTwitter; 
AttoriBackEnd.twitter.on('sync', function(){ 
    AttoreTwitter= AttoriBackEnd.twitter.get(twitter_id); 
    console.log(AttoreTwitter); // Test to see 
    // Continue code here 
});