我创建了一个jquery小部件,一切正常,直到我需要另一个实例.就在那时我注意到这两个实例共享相同的数据.该插件应该跟踪在表中检查哪些行,所以我不必每次我需要使用它们时计算它们.如果我在两个表上实例化小部件,请在一个表上单击一行 - 两个表将具有相同的数据.两个表都会发生这种情况.我只创建了几个jquery小部件,所以我不确定这是怎么发生的,但是我已经完成了代码并且可以看到它发生了.
好像我错误地使用了widget工厂.在此先感谢您的帮助!
这是小部件代码.
$.widget('ui.selectAndFilter', {
_init: function () {
},
_create: function () {
var self = this;
self.options.$mainTable = $(self.element).addClass(this.options.cssWidgetClass);
self.options.$mainTable.find('tbody tr').bind('click', function (e) {
self._onClick(e, $(this), false);
//Need to determine what todo with last param - redrawTables
});
},
options: {
cssWidgetClass: 'select-and-filter',
cssSelectedClass: 'selected',
$mainTable: {},
childTables: [],
canMultiSelect: false,
clickFinishedCallbacks: [],
minCount: 1
},
destroy: function () {
$(this.element).removeClass(this.options.cssWidgetClass);
},
_checkedIds: [],
checkRow: function ($tr) {
if ($.isDigit($tr))
$tr = $(this.options.$mainTable.find('tbody tr:eq(' + $tr …Run Code Online (Sandbox Code Playgroud) 我知道有很多委托/功能示例,但我找不到任何适合我的例子,或者我只是不理解它们.
我正在使用asp.net MVC作为一个网站,该网站需要一些Web服务调用,以便外部应用程序与我的应用程序进行交互.这些都需要一个函数来执行(转到db和whatnot),并且每次都返回一个类似的数据模型.我想在try/catch中包装每个调用并填充模型.
这是每次调用时发生的通用代码.
var model = new ResponseDataModel();
try
{
//execute different code here
}
catch (Exception ex)
{
model.Error = true;
model.Message = ex.ToString();
}
return View(model); // will return JSON or XML depending on what the caller specifies
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的控制器方法/功能之一
public ActionResult MillRequestCoil()
{
var model = new ResponseDataModel();
try
{
/* edit */
//specific code
string coilId = "CC12345";
//additional code
model.Data = dataRepository.doSomethingToCoil(coilId);
//replaced code
//model.Data = new { Coil = coilId, M3 = "m3 message", …Run Code Online (Sandbox Code Playgroud)