将错误元素传递给kendo dataSource

时间:2017-03-31 06:45:34

标签: javascript kendo-ui kendo-datasource

我正在为多个kendo元素使用一个dataSource。是否有一种简单的方法可以将错误元素传递给dataSource,如果出现错误,可以显示错误?

var countryDataSource = new kendo.data.DataSource({
  transport: {
    read: function (options) {     
      $.ajax({
        url: utils.createUrl("codelist/GetCountries"),
        success: function (result) {
          // notify the data source that the request succeeded
          options.success(result);
        },
        error: function (response) {
          // notify the data source that the request failed
          // that.displayError(alertContainer, response.status.toString() + "[" + response.statusText + "]");
          options.error(response);
        }
      });
    }
  }
});

$("[data-id=loadingLocationCountry]").kendoDropDownList({
  autoBind: false,
  // how can I pass error element e.g. countryDataSource($(errorElement)))
  dataSource: countryDataSource 
});    

$("[data-id=unloadingLocationCountry]").kendoDropDownList({
  autoBind: false,
  dataSource: countryDataSource
});       

我只提出了这个解决方案,但为每种用法创建了新的dataSource (新实例)

var countryDataSource = function(errorContainer) {
   return new kendo.data.DataSource({
      ....
      error: function (response) {
      // notify the data source that the request failed
      that.displayError(that.errorContainer, response.status.toString() + "[" + response.statusText + "]");
      options.error(response);
    }
   });
}

$("[data-id=loadingLocationCountry]").kendoDropDownList({
  ..
  dataSource: countryDataSource($("[data-id=loadingCountryErrorContainer]")) 
});  

0 个答案:

没有答案
相关问题