【问题标题】:how to render data to select2 using backbone marionette js如何使用骨干木偶js将数据呈现给select2
【发布时间】:2013-06-25 10:08:32
【问题描述】:

我正在使用select2 我能够呈现示例数据但真的不知道如何与来自服务器端的数据集成。

以下是我的选择框:

<select id="fund-code" tabindex="1" style="width:200px;">
                <option value=""><option>
                <option value="1">Mustard</option>
                <option value="2">Ketchup</option>
                <option value="3">Relish</option>
            </select> 

视图的onShow我做了以下操作:

$("#fund-code").select2({
                 placeholder: "Select Fund Code",
                 allowClear: true
             });

之后如何将数据从服务器端放到这个选择框??

请建议我这样做的方法。

【问题讨论】:

    标签: javascript marionette jquery-select2


    【解决方案1】:

    我能做到:

    创建模型:

    var FetchMasters = Backbone.Model.extend({
            url : Hexgen.getContextPath("/referencedata/portfolios")
        });
    

    附加如下选项:

     var fetchMasters = new FetchMasters();
    
                    fetchMasters.fetch({
                        success : function() {
                            for(var masterNum in fetchMasters.attributes) {
                                $("#fund-code").append("<option>" + fetchMasters.attributes[masterNum].portfolio  + "</option>");
                            }
                        }
                    });
    
                    $("#fund-code").select2({
                        placeholder: "Select Fund Code",
                         allowClear: true
                    });
    

    【讨论】:

      猜你喜欢
      • 2023-04-09
      • 2013-06-06
      • 1970-01-01
      • 2013-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多