2013-08-28 3 views
0

Я пытаюсь разобраться с передачей данных на сервер.Как запустить загрузку событий нажатием кнопки?

Моя проблема:

Ext.onReady(function(){ 

Ext.define('Person', { 
     extend: 'Ext.data.Model', 
     idProperty: 'PersonID', 
     fields: [{ 
      name: 'PersonID', 
      type: 'int' 
     }, .......], 
     proxy: { 
        type: 'ajax', 
        api: { 
          read: '1.php?id=90', 
          create: 'create.php', 
          update: 'upd.php', 
          destroy: 'delete.php' 
         } 
      } 
    }); 
    Person.load(1, { 
     //callback который будет выполнен когда запрос пройдет.... 
      callback: function(p, operation){ 

       //p -это текущий объект 
alert(p.get('Name')) 

console.log(p.get('PersonID')); //1 
console.log(p.get('Salary')) //300 

//document.getElementsByTagName('p')[0].innerHTML='<input type="button" value="click" onclick="function(){p.load()}">' 
//Uncaught ReferenceError: p is not defined ? 
//Uncaught SyntaxError: Unexpected token ( 

      } 
      }); 

person=new Person; 

Приведенный выше код работает. Как запустить событие load() нажатием кнопки? Надеюсь, вы можете мне помочь Спасибо.

ответ

3

Вы имеете в виду кнопка нажата -> нагрузка Person

HTML

<div id="btn">Button</div> 

Javascript

Ext.define('Person', { 
    extend: 'Ext.data.Model', 
    fields: ['id', 'name'], 
    proxy: { 
     type: 'ajax', 
     api: { 
      read: '/someurl' 
     }, 
     reader: { 
      type: 'json', 
      root: 'data', 
      successProperty: 'success', 
      totalProperty: 'total' 
     } 
    } 
}); 

Ext.onReady(function(){ 
    document.getElementById('btn').addEventListener('click', function(){ 
     Person.load(1); 
    }) 
}); 
+0

Совершенная. благодаря –

Смежные вопросы