我有这个代码,
try:
print "what"
newClassName = CourseNameAndCodeAssociation.objects.get(departmentCode__iexact = nameAndNumberStore[0])
print newClassName
except:
print "HAHA"
Run Code Online (Sandbox Code Playgroud)
这总是打印"HAHA",尽管事实上我在控制台中运行newClassName = ...代码并且它有效.
为什么会这样?
编辑
def newGetAllInformation(searchTerm):
nameAndNumberStore = modifySearchTerm(searchTerm)
urlStore = modifyUrl(nameAndNumberStore) # need to make the change here -- why not I go to the site, check for Course name - if that is not there switch, if it is then scrape
soup = getHtml(urlStore)
storeOfBooks = []
storeOfBooks = scrape(soup,nameAndNumberStore)
print nameAndNumberStore[0]
try:
newClassName = CourseNameAndCodeAssociation.objects.get(departmentCode__iexact = nameAndNumberStore[0])
nameAndNumberStore = modifySearchTerm(newClassName.departmentName + " …
Run Code Online (Sandbox Code Playgroud) 如果特定字段更改为特定值,是否可以侦听集合中模型的更改?
我知道像'change:fieldName'这样的东西存在,我正在找'likeTo:fieldName = true'之类的东西
所以我想要匹配这样的东西 -
foo <TEST>something something </TEST> blah
Run Code Online (Sandbox Code Playgroud)
我想要一个让我成为foo的正则表达式,但不会得到我的东西.我正在考虑使用类似这样的正则表达式
(\w\s)<
Run Code Online (Sandbox Code Playgroud)
有一个负面的预测,但我不知道如何在这种情况下使用它.
其他情况 -
something something foo <TEST> something something </TEST> blah
Run Code Online (Sandbox Code Playgroud) 所以我想出了如何将数据钻取到频率表 -
Overall.Cond Freq
235 1 0
236 2 0
237 3 1
238 4 1
239 5 9
240 6 1
241 7 1
242 8 1
243 9 1
Run Code Online (Sandbox Code Playgroud)
我想从中绘制直方图,但是当我做hist(dataFrameName)时,我得到了这个错误
Error in hist.default(veenker) : 'x' must be numeric
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况,我该如何解决这个问题呢?
所以我希望能够弄清楚我的页面的哪个部分被点击了.无法保证元素全部出现在页面上,这意味着我需要使用像jquery delegate这样的东西.
一种方法是遍历DOM中的所有元素,然后将事件处理程序附加到每个元素 - 但这将是缓慢而复杂的 - 每次动态添加新的html时,我必须重新附加所有处理程序,或找出已添加的html的子集.
另一种方法是使用事件冒泡 - 所以向文档或正文添加一个事件处理程序并依赖于冒泡的事件
这样的事情
$('body').delegate('div', 'click', function(e){
dummyId++;
console.log(e);
console.log(e.currentTarget);
console.log("=====");
});
Run Code Online (Sandbox Code Playgroud)
但是,在使用此代码后,当我单击页面上的按钮时,我得到了按钮周围的div,而不是实际的按钮.换句话说,上述内容太具体了.此外,我觉得原始选择器应该是文档,而不是body标签.
要清楚,我想知道何时在我的页面上点击任何元素 - 我该怎么做?
谢谢
所以我用.on尝试了这段代码
$(document).on('click', function(e){
console.log("EVENT DUMMY ID");
console.log(e.target);
console.log("=====");
});
Run Code Online (Sandbox Code Playgroud)
但是,当我点击我的应用程序中的按钮时,没有任何内容被触发 - 当我点击其他元素时,控制台日志会运行.
我知道如果没有更多背景,这可能很难回答 - 你还需要什么?
根据我的理解,新容器在死后不应该保留数据。
现在我有两个 Dockerfile。一个用于我的应用程序,另一个用于为数据库做种子。
这是我的项目结构
/
package.json
Dockerfile
docker-compose.yml
mongo-seeding/
Dockerfile
seedDatabase.mjs
Run Code Online (Sandbox Code Playgroud)
这是我的seedDatabase
样子
import mongodb from "mongodb";
import data from "./dummyData";
// Connection URL
const url = "mongodb://mongo:27017/poc";
async function mongoSeeder() {
try {
// first check to see if the database exists
const client = await mongodb.MongoClient.connect(url);
const db = client.db("poc");
const questionCollection = await db.createCollection("question");
const answerCollection = await db.createCollection("answer");
await questionCollection.insertMany(data.questions);
await answerCollection.insertMany(data.answers);
} catch (e) {
console.log(e);
}
}
mongoSeeder();
Run Code Online (Sandbox Code Playgroud)
这就是我Dockerfile
为数据库播种的样子
FROM node:10 …
Run Code Online (Sandbox Code Playgroud) 这是Backbone和下划线js的新手.
我有一组数组,我想转换为模型集合.
所以它就像
{ {1, 2, 3, 4}, {5, 6, 7, 8}}
Run Code Online (Sandbox Code Playgroud)
第二级数组是进入骨干模型的.现在,我有
collection.reset(_.map(results, (indvidualResults) -> new model(individualResults))
Run Code Online (Sandbox Code Playgroud)
哪个不起作用,当我做一个console.log(collection.pop)我得到一个打印出来的功能.我想这是因为我正在使用一组数组(但我可能是错的).如何将第二个数组转换为模型然后将其放入集合中?
我正在尝试删除发生的逗号
[,{
Run Code Online (Sandbox Code Playgroud)
我在这里尝试了两件具有lookbehind和lookahead的东西 -
首先是
"(?=\\[),(?=})"
Run Code Online (Sandbox Code Playgroud)
第二个是放入(?=[),(?=})
Pattern.quote().
然后我做了String.replaceAll(regex,"")
,但它不起作用.
我在哪里看错了?
我正在学习初学者节点书中的教程,我正在编写这段代码.
var body = '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8"/>
</head>
<body>
<form action="/upload" method="post">
<textarea name="text" rows="20" cols="60"></textarea>
<input type="submit" value="Submit text"/>
</form>
</body>
</html>';
response.writeHead(200,{"Content-Type" : "text/plain"});
response.write(body);
response.end();
Run Code Online (Sandbox Code Playgroud)
我把它分开了,但是我知道我需要将它全部放在一行上,当我这样做时,textarea没有出现,所写的html出现在屏幕上.
我把它分开了,因为我不确定html是否正确.
出了什么问题?
所以我有这个代码 -
bars.
append('rect')
.attr('x', 0)
.attr('y', (d, i) ->
return yScale(i)
).attr('width', (datum) ->
return xScale(datum.freq)
)
.attr('height', barHeight)
.attr('fill', 'blue')
.attr('class', 'bar')
.on('click', ->
bars.selectAll('rect').attr('fill', '#0000ff')
currentFill = d3.select(this).style('fill')
nextColor = {}
if currentFill == '#0000ff'
nextColor = '#ff0000'
else
nextColor = '#0000ff'
d3.select(this).style('fill', nextColor)
)
Run Code Online (Sandbox Code Playgroud)
但是,bars.selectAll('rect')不会改变矩形的颜色.为什么?
javascript ×4
backbone.js ×2
coffeescript ×2
python ×2
regex ×2
collections ×1
d3.js ×1
django ×1
docker ×1
dom ×1
events ×1
java ×1
jquery ×1
models ×1
mongodb ×1
node.js ×1
r ×1