2014-10-29 104 views
1

我正在尝试在页面中插入一个控件组小部件,但是当我呼叫controlgroup()时,重排是不正确的。所有预期的按钮都显示为链接(Chrome 38.0.2125.101 m)。jQuery-Mobile controlgroup does not render

我假设这是我正在做的事情,而不是一个错误,因为演示似乎很好地工作。我错过了一个步骤吗?

这里是我的示例代码: http://jsfiddle.net/Lwr4mm4v/5/

function Body() { 
    this.left_buttons = $('<div data-role="controlgroup"></div>').appendTo('div'); 

    this.save_button = $('<a href=# data-role="button" id="save">save description</a>').appendTo(this.left_buttons); 
    this.run_button = $('<a href=# data-role="button" id=\"exec\">run description</a>').appendTo(this.left_buttons); 
    this.stop_button = $('<a href=# data-role="button" id=\"stop\">stop description</a>').appendTo(this.left_buttons); 
    this.add_button = $('<a href=# data-role="button" id="add">add state</a>').appendTo(this.left_buttons); 

    this.left_buttons.controlgroup(); 
} 

var test = new Body(); 

感谢

回答

0

您使用的是旧版本的JQM这需要调用额外的方法.trigger("create")

建议您使用JQM 1.4.4,您不必使用任何其他方法。

+0

我还是couldn不能用.trigger(“create”)渲染它,但是,移到1.4.0就可以解决这个问题。谢谢! – devanl 2014-10-30 12:54:30

+0

@devanl我会延续我的回答。不过,我建议使用最新版本的JQM。 – Omar 2014-10-30 12:55:23

0

纵观最新的文档,一个增加了一类= “UI-BTN” 锚,你希望元素用作按钮。

这里是实现你的目标的一些示例代码:

function Body() { 
    this.left_buttons = $('<div data-role="controlgroup" data-type="horizontal"></div>').appendTo('#root'); 

    this.save_button = $('<a href="#" id="save" class="ui-btn ui-corner-all">Save</a>').appendTo(this.left_buttons); 
    this.run_button = $('<a href="#" id="exec" class="ui-btn ui-corner-all">Run</a>').appendTo(this.left_buttons); 
    this.stop_button = $('<a href="#" id="stop" class="ui-btn ui-corner-all">Stop</a>').appendTo(this.left_buttons); 
    this.add_button = $('<a href="#" id="add" class="ui-btn ui-corner-all">Add</a>').appendTo(this.left_buttons); 

    this.left_buttons.controlgroup(); 
} 

VAR测试=新的机构();

我建立了一个新的样本说明的jsfiddle,可以在这里找到:

jsFiddle

参见本文档上使用 “Controlgroup窗口小部件”:

Control Group Widget