Jav*_*ons 0 html dynamic backbone.js marionette
如何在运行时将值动态传递给Marionette.CompositeView?像在java中我们创建一个类似如下的方法
package com.test.poc;
public class SampleMethod {
    public int add(int a, int b) {
        return a + b;
    }
    public static void main(String[] args) {
        SampleMethod method = new SampleMethod();
        int firstValue = 90, secondValue = 90;
        System.out.println("add : " + method.add(firstValue, secondValue));
    }
}
以上是任何人都可以理解的简单java代码,如上所述如何创建和传递参数Marionette.CompositeView并对其进行处理?
最好的祝福
在您实现视图的那一刻,您可以传递您想要的任何参数.通常,您传递要在compositeView中呈现的模型和集合,但如果需要,您可以传递更多数据.
 var MyCompositeView = Backbone.Mationette.CompositeView.extend({
     initialize : function (options){
        this.dataValue = options.dataValue1;
        this.helperObject = options.helperObject;
        this.useValues();
     },
     useValues: function () {
       console.log(this.dataValue);
     }
 });
 var helperObject = { 
     value3 : "I have a value",
     value4 : "I dont!"
 }; /// a js object literal
 var myModel = new MyModel();
 var myCollection = new MyCollection();
 var myCompositeView = new MyCompositeView({model:myModel,
                                            collection:myCollection,
                                            helperObject:helperObject,
                                            dataValue1:"Hi there"});
注意我在当时传递了4个值以使视图具体化,而我只读了其中两个,模型和集合将由木偶处理,但另外两个你可以在初始化函数中读取它们.
希望有所帮助.