致力于在Coffeescript中重写我的网站的前端.我理解如何将click函数绑定到类.
$('.song').click ->
//code
Run Code Online (Sandbox Code Playgroud)
但是,我遇到了动态加载内容的一些问题.我知道在JQuery中,解决方法是使用"On"函数,如下所示:
$(document).on('click', '.song', function(){
//code
});
Run Code Online (Sandbox Code Playgroud)
但我不确定这是如何转化为咖啡因的.我的印象是火箭箭头 - >转换为javascript中的匿名函数,但如果函数是其中一个参数,它是如何工作的?我尝试了很多不同的语法,但它们似乎都不起作用,谢谢!
我目前正在使用省略号来截断多个行长的订单列表.但是,太长并且需要省略号的li会自动删除左侧的数字.有没有办法防止这种情况发生?
没有css,list-items有数字.
<style>
#test li {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
<ol id="test" style="width:100px;">
<li>test1</li>
<li>test1</li>
<li>toooooooooooooooooo loooooooooooooooooonnnnnnnnnnnnnnggggggg</li>
<li>test1</li>
<li>test1</li>
<li>test1</li>
</ol>
Run Code Online (Sandbox Code Playgroud) 我收到错误"未定义的变量:C:\ wamp\www\DGC\classes\DateFilter.php中的间隔"
这是我的DateFilter类的代码:
class DateFilter extends Filter
{
//@param daysOld: how many days can be passed to be included in filter
//Ex. If daysOld = 7, everything that is less than a week old is included
private $interval;
public function DateFilter($daysOld)
{
echo 'days old' . $daysOld .'</ br>';
$interval = new DateInterval('P'.$daysOld.'D');
}
function test()
{
echo $interval->format("%d days old </br>");
//echo 'bla';
}
}
Run Code Online (Sandbox Code Playgroud)
当我创建一个DateFilter类的新实例并调用test()时,它会给我错误.我意识到这意味着变量尚未初始化,但我知道正在调用构造函数,因为我在其中放置了一个echo语句并且它是输出的.
我也尝试过:$ this :: $ interval-> format(...); 自:: $ interval->格式(...); 但它不起作用.
我知道这可能很容易解决,对于noob问题我很抱歉.简直不敢相信这让我难过.
我在尝试将Google地图自动填充的结果偏向地图上的最后一个引脚时遇到问题.我在这里关注Google的教程:https: //developers.google.com/maps/documentation/javascript/places-autocomplete#change_search_area
我的CoffeeScript代码如下:
initSearch = ->
autocomplete = new (google.maps.places.Autocomplete)(document.getElementById('location-query'), types: [ 'geocode' ])
autocomplete.addListener 'place_changed', ->
place = autocomplete.getPlace()
addDestination(place, map, insertIndex) #places pin on map
console.log 'autocomplete bounds (before): ' + autocomplete.getBounds()
#setting bounds around new place
biasCircle = new google.maps.Circle
center: place.geometry.location
radius: 500 #in kilometers
autocomplete.setBounds(biasCircle.getBounds())
console.log 'autocomplete bounds (after): ' + autocomplete.getBounds()
Run Code Online (Sandbox Code Playgroud)
其中编译成以下javascript:
initSearch = function() {
var autocomplete;
autocomplete = new google.maps.places.Autocomplete(document.getElementById('location-query'), {
types: ['geocode']
});
return autocomplete.addListener('place_changed', function() {
var biasCircle; …Run Code Online (Sandbox Code Playgroud) 我的Jquery代码遇到了一些问题.
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function() {
$(".upvote").on("click", function()
{
alert('test');
}
});
</script>
</head>
<body style="background-color:black; color:white;">
<form action="#" method="post">
<input type="submit" class="upvote" value=" + " />
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我点击按钮时,没有任何反应.我检查并确保我有jQuery 1.7.有人可以帮忙吗?
我们目前有一个使用 PyQt 创建的功能齐全的 Gui。我的合作伙伴编写了一个函数,用于在 Tkinter 中绘制数据集。我的问题是,我们如何将两者结合起来使它们协同工作?
这是绘图功能:
def createGraph(self):
import tkinter as tk
# Send in data as param, OR
#data = [17, 20, 15, 10, 7, 5, 4, 3, 2, 1, 1, 0]
# Recieve data within function
s.send("loadgraph")
inputString = repr(s.recv(MSGSIZE))
#inputString = "-20 15 10 7 5 -4 3 2 1 1 0"
print(inputString)
data = [int(x) for x in inputString.split()]
root = tk.Tk()
root.title("FSPwners")
screen_width = 400
screen_height = 700
screen = tk.Canvas(root, width=screen_width, height=screen_height, bg= …Run Code Online (Sandbox Code Playgroud) 首先,我不是在寻找实际的模糊匹配算法。我们同时使用骰子系数和编辑距离。我正在寻找利用这些算法的最聪明的方法。
目标:
我正在尝试按文本段落中出现的顺序检测城市名称。我们有大约 100 万个地点名称的列表。我想搜索一段文本,并检测这些位置之一何时存在,然后存储该城市。地点名称可以是单个或多个单词。
示例段落:
嗨妈妈!萨姆和我正在考虑下个月穿越加拿大的公路旅行。我们知道我们已经可以住在约翰在魁北克市的家里了。我知道你在加拿大旅行过很多次,所以我想听听您的建议。
就像我说的,我们将从魁北克市出发,然后可能开车到 米拉米奇,然后前往哈利法克斯。两天后我们要去 布雷顿角。最后,我们想去艾德维科特港看看芬迪湾、迪格比和圣伊丽莎白码头等景点
以后再聊!
预期成绩
问题
我当前的障碍是如何检测包含多个单词的位置名称。我知道我可以将段落分成单词,然后将它们与我的列表进行比较,例如:
这是我目前的方法,但速度非常慢且效率低下。有没有一种聪明的方法可以实现我正在寻找的目标?
这是我正在处理的网站:http: //t3kno.dewpixel.net/
如你所见,有一个运行的歌曲列表(歌曲的YouTube视频).我实现了一项功能,这样一旦完成一首歌曲播放,列表中的下一首歌曲就会自动开始播放.
当我正在尝试加载的视频已被youtube删除版权内容时,我遇到了问题.目前,我通过调用以下方式检查歌曲的状态:
player.getPlayerState()
Run Code Online (Sandbox Code Playgroud)
等待状态返回0(结束).一旦歌曲结束,我尝试加载下一首歌.一旦这首歌加载我打电话:
player.playVideo()
Run Code Online (Sandbox Code Playgroud)
但是,如果这首歌被删除,我运气不好.我想尝试找到一种方法来捕捉该事件并跳到下一首歌.但是,当我尝试播放已删除的歌曲时,没有状态变化.含义:
function onytplayerStateChange(newState) {
//do stuff
}
Run Code Online (Sandbox Code Playgroud)
从未执行过.如何检测此事件并正确处理?
在为数组赋值时遇到问题.我有一个我创建的课程Treasury.我创建了另一个类TradingBook,我希望包含一个Treasury可以从所有方法访问的全局数组TradingBook.这是我的TradingBook和Treasury的头文件:
class Treasury{
public:
Treasury(SBB_instrument_fields bond);
Treasury();
double yieldRate;
short periods;
};
class TradingBook
{
public:
TradingBook(const char* yieldCurvePath, const char* bondPath);
double getBenchmarkYield(short bPeriods) const;
void quickSort(int arr[], int left, int right, double index[]);
BaseBond** tradingBook;
int treasuryCount;
Treasury* yieldCurve;
int bondCount;
void runAnalytics(int i);
};
Run Code Online (Sandbox Code Playgroud)
这是我的主要代码,我收到错误:
TradingBook::TradingBook(const char* yieldCurvePath, const char* bondPath)
{
//Loading Yield Curve
// ...
yieldCurve = new Treasury[treasuryCount];
int periods[treasuryCount];
double yields[treasuryCount];
for (int i=0; i …Run Code Online (Sandbox Code Playgroud) 得到一些真正令人困惑的错误,并不确定为什么.这是我的代码:
//=====================WORKS=======================
TradingBook::TradingBook(const char* yieldCurvePath, const char* bondPath)
{
//...Some stuff
BaseBond* tradingBook[bondCount];
for (int i=0; i < bondCount; i++)
{
tradingBook[i] = new CouponBond(bonds[i]);
printf("Bond: %s\n"
" Price: %.3f\n"
" DV01: %.3f\n"
" Risk: %.3f\n", tradingBook[i]->getID(), tradingBook[i]->getPrice(), tradingBook[i]->getDV01(), tradingBook[i]->getRisk());
}
}
//=================DOESNT WORK======================
//Gives Error: base operand of ‘->’ has non-pointer type ‘BaseBond’
void TradingBook::runAnalytics()
{
for (int i=0; i < bondCount; i++)
{
tradingBook[i]->calcPrice(tradingBook[i]->getYield());
tradingBook[i]->calcDV01();
tradingBook[i]->calcRisk();
printf("Bond: %s\n"
" Price: %.3f\n"
" DV01: %.3f\n"
" Risk: %.3f\n", tradingBook[i]->getID(), …Run Code Online (Sandbox Code Playgroud) 这是我的原始代码:
<tr class="song" id="'.$this->i.'">
<td class="clickable" id="td1_'.$this->i.'">
...
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
而jQuery为此:
$(".clickable").click(function()
{
//
//Make only certain parts of songs clickable
//Hacky Way to Get Index
var temp = $(this).attr("id");
temp = temp.split('_');
var i = temp[1];
var status = $('#status_'+i).val();
alert('Clicked ' + i);
var maxid = $('#maxid').val();
if(status == "max") //if maximized
{
alert("max");
}
else
{
var user = $("#user_min"+i).val();
var ytcode = $("#ytcode_min"+i).val();
var title = $("#title_min"+i).val();
var artist = $("#artist_min"+i).val();
var genre = $("#genre_min"+i).val();
var …Run Code Online (Sandbox Code Playgroud) 我目前正在处理上传页面,用户在表单中输入值,然后单击"提交".我将检查表单是否已提交,如果提交表明它们不是空的.这是我目前的代码
function validPost()
{
if(isset($_POST["title"]) && //if a post has been submitted
isset($_POST["artist"]) &&
isset($_POST["genre"]) &&
isset($_POST["url"]) &&
isset($_POST["user"]) )
{
if (strlen($_POST['title']) <= 0) {
echo 'ERROR: Please enter a title. </ br>';
return false;
}
else if (strlen($_POST['artist']) <= 0) {
echo 'ERROR: Please enter an artist. </ br>';
return false;
}
else if (strlen($_POST['genre']) <= 0) {
echo 'ERROR: Please select a genre. </ br>';
return false;
}
else if (strlen($_POST['url']) <= 0) {
echo 'ERROR: Please …Run Code Online (Sandbox Code Playgroud) javascript ×3
jquery ×3
c++ ×2
click ×2
coffeescript ×2
php ×2
ajax ×1
algorithm ×1
api ×1
autocomplete ×1
class ×1
coding-style ×1
css ×1
database ×1
ellipsis ×1
forms ×1
function ×1
fuzzy-search ×1
html-lists ×1
list ×1
load ×1
pointers ×1
private ×1
pyqt ×1
pyqt4 ×1
python ×1
reference ×1
search ×1
string ×1
submit ×1
tkinter ×1
variables ×1
youtube ×1