簡體   English   中英

將模型傳遞給對象文字中的Backbone View

[英]Passing model to Backbone View in object literal

我不確定是否可以,但是我想將參數傳遞給對象文字中的函數。

這是我的對象:

var object_literal = {
    "thing" : new APP.SomeView({ model : model_to_pass, secondPart : static_model})
};

然后我想遍歷一個集合,獲取一個參考

someCollection.each(function(things) {
    //will equal "thing"
    var x = things.get("reference");

    //Then do something like this (which obviously won't work)
    layout.someRegion.show(object_literal[x](model_to_pass))
}

如您所見,“事物”是一個函數(在本例中為主視圖)。 我想傳遞“事物”參數(“ model_to_pass”)。 如何才能做到這一點?

如果使它更容易,我將使用骨干,下划線和jquery(如果它們提供了更好的解決方案)。

我認為這對於解決方案來說有點過分設計,而使用條件條件將是最好的方法。

someCollection.each(function(things) {
    //will equal "thing"
    var x = things.get("reference");

    if (x === "thing") {
        new APP.SomeView({ model : model_to_pass, secondPart : static_model}
    }
}

謝謝你們每一個人的幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM