私は通常、ページ上にグローバル変数を作成し、jsで使用します。以下のような 何か:私は必要な場所
//mypage.html
<script type="text/javascript">
var loadScansUrl = "<%=Url.Action<ReportScannerRunController>(controller => controller.LoadScans())%>";
var loadInstancesUrl = "<%=Url.Action<ReportScannerRunController>(controller => controller.LoadInstances(-1))%>";
</script>
は、その後、私はそれらを直接使用しています。だから、あなたはあなたのグローバルデータへの1つのエントリポイントがあるでしょう
var globalVariables = {};
globalVariables.someVariable = 2;
:
//myfile.js
Ext.Ajax.request({
url: loadInstancesUrl, // here is the usage!!!
headers: {
'Content-Type': 'application/json'
},
params: this.scanId,
scope: this,
success: function (response) {
var result = Ext.decode(response.responseText);
var comboData = [];
Ext.each(result.Instances, function (instance) {
comboData.push({ Value: instance });
});
instances.store.loadData(comboData);
}
});
は、おそらくそれは次のように、一つのグローバルオブジェクトにこのすべての変数を収集することをお勧めします。
これは私がこれを行う方法です