我试图从jquery插件中调用一个函数。
示例代码为:
$("#table-2").tableDnD({
onDragClass: "myDragClass",
onDrop: function(table, row) {
var rows = table.tBodies[0].rows;
var debugStr = "Row dropped was "+row.id+". New order: ";
for (var i=0; i<rows.length; i++) {
debugStr += rows[i].id+" ";
}
$(#debugArea).html(debugStr);
},
onDragStart: function(table, row) {
$(#debugArea).html("Started dragging row "+row.id);
}
});
取自http://isocra.com/2008/02/table-drag-and-drop-jquery-plugin/
的onDrop的定义是
onDrop
传递删除行时将调用的函数。该函数有2个参数:表和被删除的行。您可以使用来计算行的新顺序 table.tBodies [0] .rows。
是否可以将功能传递给它? 例如:
onDrop: doWork(table, row),
doWork在哪里:
function doWork (table, row) {
var row_id = $(row).prop('id');
}
错误是:
Uncaught ReferenceError: table is not defined(…)
与我为doDrop添加的行有关。
任何人都知道这样做? 感谢。
答案 0 :(得分:1)
写作时
onDrop: doWork(table, row),
您使用这些参数调用函数doWork
。由于table
不存在,它会抛出错误。
正确的做法是
onDrop: doWork,
这样您就可以设置要调用的功能。
答案 1 :(得分:0)
尝试:
{
"name": "angular2-quickstart",
"version": "1.0.0",
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
"license": "ISC",
"dependencies": {
"@angular/common": "2.0.0-rc.6",
"@angular/compiler": "2.0.0-rc.6",
"@angular/core": "2.0.0-rc.6",
"@angular/router": "3.1.0-beta.0",
"@angular/forms": "0.2.0",
"@angular/http": "2.0.0-rc.6",
"@angular/upgrade": "2.0.0-rc.6",
"@angular/platform-browser": "2.0.0-rc.6",
"@angular/platform-browser-dynamic": "2.0.0-rc.6",
"core-js": "^2.4.1",
"ui-router-visualizer": "^2.0.7",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.11",
"systemjs": "0.19.27",
"zone.js": "^0.6.23",
"bootstrap": "^3.3.6",
"es6-shim": "^0.35.0"
},
"devDependencies": {
"concurrently": "^2.2.0",
"lite-server": "^2.2.2",
"typescript": "^2.0.2",
"typings": "^1.3.2"
}
}