0

我在数据网格中的按钮上添加功能事件时遇到问题。
网格的数据由 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;
}

不起作用
我做错了什么?

4

1 回答 1

1

This is the basic dojox grid formatter that returns a deferred. This doesn't work with the new dojo/Deferred 1.7 API. (I just tested). So if you want to use deferred's and a grid, you should upgrade to using dgrid instead.

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;
            }
于 2013-11-07T14:59:11.427 回答