2012-07-06 27 views
0

我需要知道如何使用值爲Store的值填充Label。在我的Model中,我定義了一個名爲bookname的字段。我需要使用書名填充此標籤。如何爲標籤和文本框添加值

我知道如何爲Grid執行此操作,但不知道如何爲LabelTextfield執行此操作。

在網格中;

{ text: "Book Name", dataIndex: 'bookname'}, 

但是,我們如何爲標籤和文本字段添加值。

UPDATE

我仍然有問題。我無法將這些值設置爲標籤。 (從STORE加載後)。該標籤被顯示,但它不會使用從STORE獲得的值填充。這樣沒有錯誤。

Ext.define('Ex.view.info', { 
    extend: 'Ext.window.Window', 
    alias: 'widget.info', 
    initComponent: function() { 
     var st = Ext.getStore('peopleinformation'); 
     st.load(); 
     this.items = [ 
      { 

       xtype: 'label', 
       forId: 'myFieldId', 
       text: 'My Awesome Field', 
       name: 'personfirstname', 
       margins: '0 0 0 10' 

      } 
     ]; 
     this.callParent(arguments); 
    } 
}); 
+1

這是爲什麼降不投票評論均勻。 – Illep 2012-07-06 11:14:46

回答

2

對於剛剛設置標籤的值,你可以使用標籤 http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Label-method-setText

yourLabel.setText('value'); 

描述的setText方法對於文本字段 - http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.field.Text-method-setValue

UPDATE:

// in your store 
proxy: { 
    type: 'ajax', 
    url: 'you url', 
    method: 'GET', 
    headers: { 'Content-Type': 'application/json' }, //your response type like xml, json   
    reader: { type: 'json',    
     getResponseData: function (response) { 
      var data = Ext.decode(response.responseText); 
      //loop here , if more labels are there 
      // get the object referance of label and update that 
     } 
    } 

UPDATE: 做您嘗試過:

Ext.form.Labelable引入
text: st.yourFieldName, 
+0

我需要添加從STORE加載後的值。我有問題顯示文本(從商店)到標籤。 – Illep 2012-07-07 19:27:18

+0

簡單的方法是從商店的回覆你可以更新你的標籤。包括一些代碼 – Jom 2012-07-10 06:00:39

+0

我如何獲得'label'來更新。我的標籤在窗口內。如果您是從這裏創建窗口,我使用'ComponentQuery'來定位標籤 – Illep 2012-07-10 06:17:42

0

各種fields通常被組合爲在form項 - (見http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Panel)。表單有一個方法getForm().loadRecord(model)可將數據從模型(商店中的記錄)加載到表單中的所有字段。 PS:看起來你還沒有經過Sencha指南(http://docs.sencha.com/ext-js/4-0/#!/guide),因爲我在你的其他問題上建議你。你仍然沒有大概的想法。

+0

是的,我已閱讀文檔。但你很快就無法掌握它。我猜錯誤審判工作得很好。 – Illep 2012-07-06 11:59:20

+0

我試過了,我試圖在窗口中的標籤上顯示記錄。它不會顯示,並且在螢火蟲中沒有顯示錯誤。我在上面的帖子中添加了我的代碼。 – Illep 2012-07-07 19:26:12

+0

我在代碼中看不到任何從商店獲取數據並將其放入標籤的內容。 – sha 2012-07-07 20:05:49

0

分機4.1,其被混合到Ext.form.field.Base,使得它在Ext.form.field.Text可用。

因此,你可以撥打myTextField.setFieldLabel("My Label Text")

相關問題