我在0.8版本中試過,它按預期工作(通過AMD模式)。我對代碼做了輕微的修改,使其在0.8版本中編譯。
- 更改Script.Alert到Window.Alert
- 移除ScriptNamespace並加入[組件:ScriptAssembly( 「腳本」)]中的AssemblyInfo.cs
在S#類
using System.Html;
using jQueryApi;
namespace Echo.Web.JScript {
public class MasterTrackerActions {
private jQueryObject _source;
public MasterTrackerActions(string fundCodeSourceId) {
_source = jQuery.Select("#" + fundCodeSourceId);
_source.Change(delegate {
Window.Alert("Here we go"); //We see this fine.
LoadContent();
});
}
public void LoadContent() {
Window.Alert("Do we get here?"); //Answer is no
}
}
}
生成的JS文件是
/*! Scripts.js 1.0.0.0
*
*/
"use strict";
define('Scripts', ['ss', 'jquery'], function(ss, $) {
var $global = this;
// Echo.Web.JScript.MasterTrackerActions
function MasterTrackerActions(fundCodeSourceId) {
var $this = this;
this._source = $('#' + fundCodeSourceId);
this._source.change(function() {
alert('Here we go');
$this.loadContent();
});
}
var MasterTrackerActions$ = {
loadContent: function() {
alert('Do we get here?');
}
};
var $exports = ss.module('Scripts', null,
{
MasterTrackerActions: [ MasterTrackerActions, MasterTrackerActions$, null ]
});
return $exports;
});
現在要在HTML文件中使用它,您需要使用提供的ModuleLoader SSLoader.js或RequireJS(首選)。在這種情況下,您需要帶JQuery的RequireJS模塊。有不同的方法可以包含JQuery(這裏超出了範圍)。
HTML文件
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<script type="text/javascript" data-main="Scripts/MyScript.js" src="Scripts/require-jquery.js"></script>
<script type="text/javascript">
require(['MyScript'], function (ms) {
var tracker = new ms.MasterTrackerActions('sampleText');
console.log(tracker);
});
</script>
<textarea id="sampleText">TEST123</textarea>
</body>
</html>
哦,還有一兩件事,當控件失去焦點事件觸發...
好像你正在使用的版本0.7倍。你能發佈你生成的JavaScript嗎? – theoutlander