【问题标题】:Using Deferred with Dojo DataGrid将 Deferred 与 Dojo DataGrid 一起使用
【发布时间】:2013-08-22 07:33:06
【问题描述】:

在数据网格中的按钮上添加功能事件时遇到问题。
网格的数据由 json-rest-store 加载,buttons 列也随之加载。
每当我需要添加这个:

Spring.addDecoration(new Spring.AjaxEventDecoration({elementId: button.id, event:'onclick', params: { _eventId: "details", fragments: "content" }}));

它说没有 id 存在,因为加载还没有准备好。

我正在使用这样的延迟:

function formatDetails(fields, rowIdx, cell){

        var buttonEditLabel = dojo.byId('buttonEdit').innerHTML;

        var buttonEdit = new dijit.form.Button({
            id: rowIdx,
            type : "submit",
            label: buttonEditLabel,
            showLabel: true
        });


        dojo.style(buttonEdit.domNode, "width", "95px"); 
        dojo.style(buttonEdit.domNode, "textAlign", "center");
        dojo.style(buttonEdit.domNode.firstChild, "display", "block");

      var id;
     var deferred = new Deferred(function(reason){
          id = dojo.byId(buttonEdit.id);
      });

    deferred.progress(update);
    deferred.resolve(value);

     deferred.then(function(value){
      Spring.addDecoration(new Spring.AjaxEventDecoration({elementId: buttonEdit.id,   event:'onclick', params: { _eventId: "details", fragments: "content" }}));
      }, function(err){

      }, function(update){

      });

      return buttonEdit;
}

没用
我做错了什么?

【问题讨论】:

    标签: ajax dojox.grid.datagrid dojo


    【解决方案1】:

    这是返回延迟的基本 dojox 网格格式化程序。这不适用于新的 dojo/Deferred 1.7 API。 (我刚刚测试过)。因此,如果您想使用 deferred 和网格,则应该升级为使用 dgrid。

    fmtItem: function(value, idx){
                    if(!this.store.isItem(value)){
                        return " ";
                    }
                    var d = new dojo.Deferred();
                    var fx = function(items){
                        if(items.length){
                            d.callback(this.store.getLabel(items[0]))
                        }else{
                            d.callback(" ");
                        }
                    };
                    window.setTimeout(dojo.hitch(this, function(){
                        this.store.fetch({query: {children: value}, onComplete: fx, onError: function(e){d.errback(e)}, scope: this});
                    }), 5000);
                    return d;
                }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-05
      • 2019-01-10
      • 1970-01-01
      • 2011-02-20
      相关资源
      最近更新 更多