【问题标题】:'book' textfield does not trigger event in sencha'book' 文本字段不会触发 sencha 中的事件
【发布时间】:2015-09-01 08:20:09
【问题描述】:

我有这个代码Ext.get('book').setValue('1');

注意:加载页面,book value 设置为 1。页面加载后不加载 账面价值变为 1。

它将 book 的值设置为 1。但它不会触发 change 事件。有没有办法在页面加载后触发 change 事件?

编辑: 在 html 脚本中,

<script..>
    $(document).ready(function () { 
        $("book").on("blur", function() {
           //calls other function
        }); // not called as blur is not invoked 
    }); 
</script>

<input id="book" type="book" value="" /><br />

在 extjs 中,

var panel = Ext.create('Ext.grid.Panel', {    
id: 'panel',
columns: [
    var bookid = "new book";
      Ext.Ajax.request({
        params: { bookid: bookid},
        function: function (response) {
           Ext.get('book').setValue(bookid);
           // after setValue, book will receive a change event(e.g .blur in html) and changes other functions 
        }
      });
]
});

【问题讨论】:

  • 是的,在你的应用初始化中设置它
  • 除了在app初始化中做,还有其他方法吗?因为它是在页面加载之后,然后在设置书籍文本字段值之前触发按钮@Icepickle
  • 我认为您也可以设置一个默认值,但是您的代码示例/问题非常有限,很难看出您有什么问题。您能否提供更详细的说明(编辑您的起始帖子?)

标签: javascript html extjs sencha-architect


【解决方案1】:

您的 ajax 请求似乎格式不正确,function: function 语句将是您通常放置 success: function 的位置,如以下语句所示:

Ext.Ajax.request({
    url: 'insert-your-http-endpoint-here',
    params: {
        bookid: bookid
    },
    success: function(response){
        debugger; // -> setting this statement will show that you enter the success statement
        Ext.get('book').setValue(bookid);
    },
    failure: function(response, opts) {
        // something went wrong with your request
        console.log('server-side failure with status code ' + response.status);
    }
});

更多关于如何使用 ExtJS 或特定功能的信息,你可以在文档中找到(检查你是否有正确的版本,当然)可以找到 here

从上面的代码中,您不需要debugger 语句,但如果您想检查您是否真的进入此代码块,以及尝试设置该值时会发生什么,它可能会有所帮助。

另外,当某些东西不工作时,不要忘记检查你的控制台输出,也许有一个问题会在控制台日志中明确指出

【讨论】:

  • 是的!在我当前的代码中,它工作正常并且已设置文本字段。但不是'// setValue 之后,book 将收到一个更改事件(例如 html 中的 .blur)并更改其他功能'@Icepickle
  • 对不起,我做了一个快捷方式,但主要功能正在显示,就像你的代码一样
  • @Developps:我不确定你的意思。你的意思是在 html 控件上设置的事件没有触发,还是你有另一个控件正在监听这些事件? onblur 不会触发,因为您设置了一个值。 onchange 会,以防文本与之前的文本不同
  • 这是在 html 控件上设置的事件没有触发。我已经尝试过 Onchange 并且它也不会触发,因为它是在任何更改之前设置的@Icepickle
  • $("book").on("change", function() { ... }); // not called as change is not invoked
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-26
  • 1970-01-01
  • 2016-08-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多