我正在尝试向index.html文件中的按钮添加功能如下:我有一个按钮元素index.html
<button id="auth-button">Authorize</button>
Run Code Online (Sandbox Code Playgroud)
在main.js应用程序中,我有
require('crash-reporter').start();
console.log("oh yaeh!");
var mainWindow = null;
app.on('window-all-closed', function(){
if(process.platform != 'darwin'){
app.quit();
}
});
app.on('ready',function(){
mainWindow = new BrowserWindow({width:800, height : 600});
mainWindow.loadUrl('file://' + __dirname + '/index.html');
var authButton = document.getElementById("auth-button");
authButton.addEventListener("click",function(){alert("clicked!");});
mainWindow.openDevTools();
mainWindow.on('closed',function(){
mainWindow = null;
});
});
Run Code Online (Sandbox Code Playgroud)
但是出现如下错误:
Uncaught Exception: ReferenceError: document is not defined
在构建电子应用程序时是否可以访问DOM对象?或者是否有其他替代方法可以提供所需的功能?
我一直在使用TypeScript和KnockoutJS创建一个htmlHelper函数来编辑电子邮件列表.
电子邮件列表是一个叫做电子邮件的Knockout ObservableArray ,我有一个链接,每个项目都要删除它们.这是HTML片段:
<ul data-bind="foreach: emails" >
<li>
<a href="#" data-bind="click: $parent.deleteItem">Delete</a>
<span data-bind="text: $data"></span>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
删除链接绑定到$ parent.deleteItem这是viewmodel中的方法:
// remove item
public deleteItem(emailToDelete: string) {
// remove item from list
this.emails.remove(emailToDelete);
}
Run Code Online (Sandbox Code Playgroud)
这一切都有效,直到执行deleteItem方法.调用此方法时的"this"是数组中的项,而不是视图模型.因此this.emails是一个空引用并失败.
我知道TypeScript支持Lambda语法,但我找不到正确的写入方法(那里有几个例子).
或者我可以采取不同的方法?
我知道LINQ to SQL没有转换为SQL DateTime,string因为没有ToString().但是如何将其DateTime转换为格式化的字符串?
这是以下查询中需要帮助的行:
StartDate = string.Format("{0:dd.MM.yy}", p.StartDate)
Run Code Online (Sandbox Code Playgroud)
整个查询:
var offer = (from p in dc.CustomerOffer
join q in dc.OffersInBranch
on p.ID equals q.OfferID
where q.BranchID == singleLoc.LocationID
let value = (p.OriginalPrice - p.NewPrice) * 100 / p.OriginalPrice
orderby value descending
select new Offer()
{
Title = p.OfferTitle,
Description = p.Description,
BestOffer = value,
ID = p.ID,
LocationID = q.BranchID,
LocationName = q.CustomerBranch.BranchName,
OriginalPrice = SqlFunctions.StringConvert((decimal)p.OriginalPrice),
NewPrice = SqlFunctions.StringConvert((decimal)p.NewPrice),
StartDate = string.Format("{0:dd.MM.yy}", …Run Code Online (Sandbox Code Playgroud) 我在ASP.NET核心控制器中得到一个日期,如下所示:
public class MyController:Controller{
public IActionResult Test(DateTime date) {
}
}
Run Code Online (Sandbox Code Playgroud)
该框架能够解析日期,但只能以英文格式.当我通过04.12.2017作为日期参数时,我的意思是2017年12月4日.这将被解析为英文日期,所以我的日期对象获得2017年4月12日的价值.我尝试仅使用这篇文章添加德语,并且这个,但没有成功.
ASP.NET Core需要做什么才能以正确的德语格式自动解析日期?
更新 I尝试设置RequestLocalizationOptions
services.Configure<RequestLocalizationOptions>(opts =>
{
var supportedCultures = new[]
{
new CultureInfo("de-DE"),
};
opts.DefaultRequestCulture = new RequestCulture("de-DE");
// Formatting numbers, dates, etc.
opts.SupportedCultures = supportedCultures;
// UI strings that we have localized.
opts.SupportedUICultures = supportedCultures;
});
Run Code Online (Sandbox Code Playgroud)
还是行不通.我打电话给example.com/Test?date=12.04.2017并在我的调试器中得到了这个:
public IActionResult Test(DateTime date) {
string dateString = date.ToString("d"); // 04.12.2016
string currentDateString = DateTime.Now.ToString("d"); // 14.01.2016
return Ok();
}
Run Code Online (Sandbox Code Playgroud) 我在Exchange Online服务上有一个邮件帐户.现在我正在尝试测试我是否能够通过c#应用程序向客户(在varoius域和Microsoft Office 365上)发送邮件
我尝试实现以下代码,但我收到错误
"根据验证程序,远程证书无效."
MailMessage mail = null;
mail = new MailMessage();
string[] strToList = "abc@gmail.com"
foreach (string strID in strToList)
{
if (strID != null)
{
mail.To.Add(new MailAddress(strID));
}
}
mail.From = "demo@onmicrosoft.com";
mail.Subject = "testing"
mail.IsBodyHtml = true;
mail.Body = "mail body";
SmtpClient client = new SmtpClient("smtp.outlook.office365.com");
client.Port = 587;
client.EnableSsl = true;
client.UseDefaultCredentials = false;
NetworkCredential cred = new System.Net.NetworkCredential("demo@onmicrosoft.com", "mypassword");
client.Credentials = cred;
client.Send(mail);
Run Code Online (Sandbox Code Playgroud)
如果我做错了,请建议.非常感谢提前.
是否可以将常规锚标记指向打开用于保存文件的对话框的文件?就像网络浏览器一样.
例如:
<a download href="documents/somefile.pdf">Download</a>
Run Code Online (Sandbox Code Playgroud)
让click-tag在点击时触发Save文件对话框?
我尝试过使用file://absolute-path-to-the-dir/documents/somefile.pdf它想要在应用程序中打开文件而不是下载它.
更新:在Electron的后续版本中,我在编写此问题时使用的行为就像我想要的那样,会打开一个窗口,要求用户保存文件.
但是,在外部链接的情况下,想要保留Electron窗口仅用于内部链接并在默认操作系统选项中打开外部链接,Joshua Smith的答案可以做到这一点.
我想在这个html页面的div部分显示一个加载器GIF图像.但我无法让它发挥作用.div内容被隐藏,GIF图像消失.
CSS:
.loader {
background-image: url(image/Preloader_8.gif);
background-repeat: no-repeat;
height:100px;
width:200px;
}
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
<script type="text/javascript">
$(window).load(function() {
$(".loader").fadeOut("slow");
})
</script>
Run Code Online (Sandbox Code Playgroud)
HTML:
<body>
<div class="loader">
Loading Image
</div>
</body>
Run Code Online (Sandbox Code Playgroud) 我有一个IEnumerable的Lesson对象:
IEnumerable<Lesson> filteredLessons
Run Code Online (Sandbox Code Playgroud)
我通过以下方法将其转换为List:
ToList();
Run Code Online (Sandbox Code Playgroud)
但我希望返回的列表只包含第一个属性lessonid,而不是所有Lesson属性.
如何获取列表的特定属性而不是对象的数据?
<ul>
<li>Kelvin</li>
<li>Jerry</li>
<li>Adi</li>
<li>Dani</li>
<li>Olvin</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
如何获取<li>包含"Jerry" 的元素的索引?
我试过读这些
但是找不到答案:(你能帮助我吗?
我通过POST得到输入值,其中一些可能是ID指的是其他东西,有些从0开始.当选择ID为0的东西,或者没有值的东西时,是否有类似的方法intval()返回比0失败更有帮助的东西解析?或者我能否以某种方式区分intval()失败的结果?
例:
echo intval(null); // 0
echo intval("0"); // 0
Run Code Online (Sandbox Code Playgroud) c# ×3
javascript ×3
electron ×2
jquery ×2
linq ×2
asp.net ×1
asp.net-core ×1
dom ×1
html ×1
ienumerable ×1
knockout.js ×1
lambda ×1
linq-to-sql ×1
list ×1
loader ×1
office365 ×1
php ×1
typescript ×1