English 中文(简体)
Java variables 封存成功呼吁的变量(jquery/backbonejs/parse功能)
原标题:Javascript Keeping variables in scope on success callback (jquery/backbonejs/parse function)

下面,我利用骨干 j收集。 在请求的答复中,我谨对收集数据进行定量表示某种逻辑。 我正在修改关于育儿(来源类型)的教区法,以附上儿童收集资料(来源账户),如果实际上有来源账户,则只包括来源类型。

我不想这样做,而没有把全部数据主要装上,因此,我用javascript说出,唯一安全的道路是成功的警示。

如你在以下法典中可以看到,在教区职能范围内,我建造了一个称为“反应-目标”的新物体。 问题是,如果试图在成功呼吁中包装这一物体,则收集工作并不包括任何一包装的物体。 你们将如何改写这段话,使这项工作正确无误?

window.AdminSourceTypes = Backbone.Collection.extend({
    model: window.AdminSourceType,  
    url:  /api/sources ,   
    parse: function(response){   
        // create response object
        response_object = [];           
        x = 0;
        _.each(response, function(item){
            //get child collection (accounts) from one of "source type s" attributes
            collection = new window.AdminAccounts();
            collection.url = item.accounts_url;
            //get all accounts
            collection.fetch({ 
                //only add the source type to the response object 
                //if there are accounts associated to it             
                success: function(accounts_collection){
                    if(accounts_collection.size() > 0){
                    response_object[x] = item;      
                    }
                }
            });
            x++;
        });
        return response_object;         
    }
});
问题回答

这是我所谈到的:

    window.sources = new window.AdminSourceTypes({
      events: {
       reload : render 
      }
     render: function(){... bla bla .... }
    });

    window.sources.fetch({});

    window.AdminSourceTypes = Backbone.Collection.extend({
    model: window.AdminSourceType,
    url:  /api/sources ,
    parse: function(response){
        cmp = this;
        response_object = []; 
        x = 0;
        y = 0;
        _.each(response, function(item){‣
            collection = new window.AdminAccounts();
            collection.url = item.accounts_url;
            collection.fetch({
                success: function(data){
                    x++;
                    if(data.size()>0){
                        item.accounts = collection;
                        window.sources.add(item);
                        window.sources.trigger( reload );
                    }   
                }   
            }); 
        }); 
    }   
}); 

因此,我们不要等待成功退步,而只想让 par子法不会再回去,如果它满足我的境遇,就把这个物品添加到收集中。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签