Javascript jquerymobile以奇怪的方式呈现布局

Javascript jquerymobile以奇怪的方式呈现布局,javascript,jquery,jquery-mobile,underscore.js,Javascript,Jquery,Jquery Mobile,Underscore.js,我正在使用木偶和jQuery Mobile创建一个应用程序,但呈现的html代码有问题。 要编译html代码,我在CompositeView的模板方法中使用.template(htmlCode,modelVars)(下划线的方法) 我编写代码是为了实现我的目标: Marionette.CompositeView.extend({ template : function() { var tpl = App.Templates.get('my-vehicles-table')

我正在使用木偶和jQuery Mobile创建一个应用程序,但呈现的html代码有问题。 要编译html代码,我在CompositeView的
模板
方法中使用
.template(htmlCode,modelVars)
(下划线的方法)

我编写代码是为了实现我的目标:

Marionette.CompositeView.extend({
    template : function() {
        var tpl = App.Templates.get('my-vehicles-table'); //returns html template
        return _.template(tpl, {});
    },
    itemView : Module.View.MyVehicleRow,
    itemViewContainer: "tbody"
  });
表行在
tpl
变量中定义时由JQM呈现:

var htmlCode = '<table data-role="table" id="my-vehicles-table" data-mode="reflow" class="ui-responsive table-stroke">
            <thead>
                <tr class="ui-bar-d">
                    <th data-priority="2">Reg No.</th>
                    <th>VIN</th>
                    <th data-priority="3">Model</th>
                    <th data-priority="1">Type</th>
                    <th data-priority="5">Client</th>
                </tr>
            </thead>
            <tbody>
                <tr><td>DW 12345</td><td>QWER123</td><td>F12</td><td>No Contract</td><td>John Smith</td></tr>
            </tbody>
    </table>';
和表行仅通过CompositeView方法插入到

有趣的是,如果在
tpl
(内部
)中声明了一些行,并且CompositeView方法插入了动态的其他行,则结果表中呈现了好的行和坏的行。如果在模板中声明,则这些是好的,如果由CompositeView添加,则这些是坏的

我想要什么?让jQuery Mobile呈现所有行(在呈现页面时将带有特殊属性的html添加到标记中)

谢谢

---编辑---

当然,问题在于时机。在呈现视图组件(VC)之前,必须确保已获取所有数据。如果您想将数据从异步请求放到VC,在初始化它的新实例之前,请检查模型/集合的同步事件

即:

 var tpl = '<table data-role="table" id="my-vehicles-table" data-mode="reflow" class="ui-responsive table-stroke">
                <thead>
                    <tr class="ui-bar-d">
                        <th data-priority="2">Reg No.</th>
                        <th>VIN</th>
                        <th data-priority="3">Model</th>
                        <th data-priority="1">Type</th>
                        <th data-priority="5">Client</th>
                    </tr>
                </thead>
                <tbody></tbody>
        </table>';
    var collection = new CustomCollection();
    collection.fetch();
    $.when(collection).done(function(collectionRecords){
        collectionRecords.on('sync', function() {
            //collectionRecords has all the data you want to put into the VC
        });
    });