0 / 0 / 0
Регистрация: 13.12.2017
Сообщений: 32
1

Yes/no при изменении Checkbox

20.06.2018, 17:03. Показов 2655. Ответов 0
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Всем привет!
Только начал розбираться с extjs .Не получаеться втулить checkbox.
Точнее не получаеться сделать так, чтобы когда менял чекбокс вместо true/false было yes/no.

https://fiddle.sencha.com/#view/editor&fiddle/2i9l

Javascript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
Ext.onReady(function () {
  Ext.define('TechZoo.model.Book', {
    extend: 'Ext.data.Model',
    fields: [
      {name: 'title', type: 'string'},
      {name: 'author',  type: 'string'},
      {name: 'price', type: 'int'},
      {name: 'released',  type: 'boolean'}
    ]
  });
 
  Ext.define('TechZoo.store.Books', {
    extend  : 'Ext.data.Store',
    model   : 'TechZoo.model.Book',
    fields  : ['title', 'author','price', 'rel'],
    data    : [
      { title: 'JDBC, Servlet and JSP',
        author: 'Santosh Kumar', price: 300, rel : false },
      { title: 'Head First Java',
        author: 'Kathy Sierra', price: 550, rel : true },
      { title: 'Java SCJP Certification',
        author: 'Khalid Mughal', price: 650, rel : false },
      { title: 'Spring and Hinernate',
        author: 'Santosh Kumar', price: 350, rel : true },
      { title: 'Mastering C++',
        author: 'K. R. Venugopal', price: 400, rel : false }
    ]
  });
 
  Ext.define('TechZoo.view.BooksList', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.bookslist',
    title: 'Books List ',
    store: 'Books',
    initComponent: function () {
      this.tbar = [{
        text    : 'Add Book',
        action  : 'add',
        iconCls : 'book-add'
      }];
      this.columns = [
        { header: 'Title', dataIndex: 'title', flex: 1 },
        { header: 'Author', dataIndex: 'author' },
        { header: 'Price', dataIndex: 'price' , width: 60 },
        { header: 'Released', dataIndex: 'rel', width: 80 },
        { header: 'Action', width: 50,
          renderer: function (v, m, r) {
            var id = Ext.id();
            var max = 15;
            Ext.defer(function () {
              Ext.widget('image', {
                renderTo: id,
                name: 'delete',
                src : 'images/book_delete.png',
                listeners : {
                  afterrender: function (me) {
                    me.getEl().on('click', function() {
                      var grid = Ext.ComponentQuery.query('bookslist')[0];
                      if (grid) {
                        var sm = grid.getSelectionModel();
                        var rs = sm.getSelection();
                        if (!rs.length) {
                          Ext.Msg.alert('Info', 'No Book Selected');
                          return;
                        }
                        Ext.Msg.confirm('Remove Book',
                          'Are you sure you want to delete?',
                          function (button) {
                            if (button == 'yes') {
                              grid.store.remove(rs[0]);
                            }
                        });
                      }
                    });
                  }
                }
              });
            }, 50);
            return Ext.String.format('<div id="{0}"></div>', id);
          }
        }
      ];
      this.callParent(arguments);
    }
  });
 
    Ext.define('TechZoo.view.BooksForm', {
      extend  : 'Ext.window.Window',
      alias   : 'widget.booksform',
      title   : 'Add Book',
      width   : 350,
      layout  : 'fit',
      resizable: false,
      closeAction: 'hide',
      modal   : true,
      config  : {
        recordIndex : 0,
        action : ''
      },
      items   : [{
        xtype : 'form',
        layout: 'anchor',
        bodyStyle: {
          background: 'none',
          padding: '10px',
          border: '0'
        },
        defaults: {
          anchor: '100%'
        },
        items : [{
          xtype : 'textfield',
          name  : 'title',
          fieldLabel: 'Book Title'
        },{
          xtype : 'textfield',
          name: 'author',
          fieldLabel: 'Author Name'
        },{
          xtype : 'textfield',
          name: 'price',
          fieldLabel: 'Price'
        },{
          xtype : 'checkbox',
          name: 'rel',
          fieldLabel: 'Released',
          trueText: 'Yes',
        falseText: 'No'
        }]
      }],
      buttons: [{
        text: 'OK',
        action: 'add'
      },{
        text    : 'Reset',
        handler : function () {
          this.up('window').down('form').getForm().reset();
        }
      },{
        text   : 'Cancel',
        handler: function () {
          this.up('window').close();
        }
      }]
    });
 
  Ext.define('TechZoo.controller.Books', {
    extend  : 'Ext.app.Controller',
    stores  : ['Books'],
    views   : ['BooksList', 'BooksForm'],
    refs    : [{
      ref   : 'formWindow',
      xtype : 'booksform',
      selector: 'booksform',
      autoCreate: true
    }],
    init: function () {
      this.control({
        'bookslist > toolbar > button[action=add]': {
          click: this.showAddForm
        },
        'bookslist': {
          itemdblclick: this.onRowdblclick
        },
        'booksform button[action=add]': {
          click: this.doAddBook
        }
      });
    },
    onRowdblclick: function(me, record, item, index) {
      var win = this.getFormWindow();
      win.setTitle('Edit Book');
      win.setAction('edit');
      win.setRecordIndex(index);
      win.down('form').getForm().setValues(record.getData());
      win.show();
    },
    showAddForm: function () {
      var win = this.getFormWindow();
      win.setTitle('Add Book');
      win.setAction('add');
      win.down('form').getForm().reset();
      win.show();
    },
    doAddBook: function () {
      var win = this.getFormWindow();
      var store = this.getBooksStore();
      var values = win.down('form').getValues();
 
      var action = win.getAction();
      var book = Ext.create('TechZoo.model.Book', values);
      if(action == 'edit') {
        store.removeAt(win.getRecordIndex());
        store.insert(win.getRecordIndex(), book);
      }
      else {
        store.add(book);
      }
      win.close();
    }
  });
 
  Ext.application({
    name  : 'TechZoo',
    controllers: ['Books'],
      launch: function () {
        Ext.widget('bookslist', {
          width : 500,
          height: 300,
          renderTo: 'output'
        });
      }
    }
  );
});


Добавлено через 50 минут
спасибо, уже сам решил проблему . Если кто знает как лучше.пишите

таким образом :
Javascript
1
2
3
4
5
6
7
  xtype: 'checkbox',
    name: 'rel',
    fieldLabel: 'Released',
    trueText: 'Yes',
    falseText: 'No',
    uncheckedValue: 'No',
    inputValue: 'Yes'
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
20.06.2018, 17:03
Ответы с готовыми решениями:

Создаем события при изменении checkbox
Надо создать событие на checkbox даный варин работае: &lt;script type=&quot;text/javascript&quot;&gt; ...

Не всегда срабатывает onClick при изменении состояния checkBox
Ребят, такая проблема: делаю АРМ кое какой, и в начале заметил что onClick срабатывает при...

Многотабличный запрос при изменении значения свойства CheckBox
Привет! По условию задания необходимо создать приложение Windows Forms, которое выбирает из базы...

Обновление состояний checkBox при изменении состояния соответствующего comboBox
Доброго времени суток, возник вопрос: Как при смене значения comboBox изменять состояния checkBox?...

0
20.06.2018, 17:03
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
20.06.2018, 17:03
Помогаю со студенческими работами здесь

Добавление и удаление текста в файл при изменении значения CheckBox
3) Как на CheckBox прописать добавление текста в текстовый файл и при снятии галочки чтобы...

Как при изменении свойства Enabled у Checkbox не менять цвет его текста?
При изменении свойства Enabled у Checkbox цвет меняется на черный. Как запретить его менять? В...

Как при программном изменении свойства checked checkbox не выполнять событие onclick?
Если прописать CheckBox1.Checked:=False;, то выполнится oncklick. Как этого избежать, при этом...

Создать форму с CheckBox, при изменении свойства Checked менять цвет формы
Элемент управления CheckBox. Создать форму с CheckBox при изменении свойства Checked менять цвет...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
1
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru