2014-10-29 72 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