有什么区别.on,.listenTo,和.bind?
我在这里测试了它们,它们看起来做同样的事情:回调.
var NewStatusView = Backbone.View.extend({
events: {
"submit form": "addStatus"
},
initialize: function(options) {
// using .on
//this.collection.on("add", this.clearInput, this);
// or using bind:
//_.bindAll(this, 'addStatus', 'clearInput');
//this.collection.bind('add', this.clearInput);
// or using listenTo:
_.bindAll(this, 'addStatus', 'clearInput');
this.listenTo(this.collection, 'add', this.clearInput) ;
},
addStatus: function(e) {
e.preventDefault();
this.collection.create({ text: this.$('textarea').val() });
},
clearInput: function() {
this.$('textarea').val('');
}
});
Run Code Online (Sandbox Code Playgroud)
什么时候使用哪种情况最好?
我正在使用apollo-client库来查询来自我的Graphql服务器的数据.一些查询通过apollo轮询能力每隔5秒发送到服务器.
有一种通用的方法可以为从我的客户端轮询发送的所有请求添加自定义标头吗?
谢谢你的帮助 :)
假设有一些<Form>组件.它可以通过@cancel附加到它的事件监听器来调用,如果是这种情况,我想显示触发此事件的取消按钮.如果没有@cancel事件,则不应显示取消按钮.
有没有办法检查组件是否附加了事件监听器?
目前我这样做:
<template>
<form>
<button v-if="cancelEventPassed" @click="$emit('cancel')">Cancel</button>
</form>
</template>
Run Code Online (Sandbox Code Playgroud)
并称之为:
<Form :cancelEventPassed="true" @cancel="handle_cancel" />
Run Code Online (Sandbox Code Playgroud)
或
<Form/>
Run Code Online (Sandbox Code Playgroud)
是否有可能在不使用任何其他属性的情况下实现这一目标cancelEventPassed?
我有基于Cordova的应用程序,基于主干js.
但是当我尝试创建android构建时,它会给我以下错误.
[exec] > Could not resolve all dependencies for configuration ':_armv7DebugApkCopy'.
[exec] > Could not resolve org.xwalk:xwalk_core_library:23+.
[exec] Required by:
[exec] :android:unspecified
[exec] > Could not resolve org.xwalk:xwalk_core_library:23+.
[exec] > Failed to list versions for org.xwalk:xwalk_core_library.
[exec] > Unable to load Maven meta-data from https://download.01.org/crosswalk/releases/crosswalk/android/maven2/org/xwalk/xwalk_core_library/maven-metadata.xml.
[exec] > Could not GET 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2/org/xwalk/xwalk_core_library/maven-metadata.xml'.
Received status code 403 from server: Forbidden
Run Code Online (Sandbox Code Playgroud)
它似乎试图从这个网址获取一些数据:https://download.01.org/crosswalk/releases/crosswalk/android/maven2/org/xwalk/xwalk_core_library/maven-metadata.xml19
在这个时刻,正在抛出403.我尝试在关闭互联网访问的情况下构建它,以防只有在可用时才需要它,但它尝试并且(显然)失败了.
此构建是否依赖于活动的Internet连接和可能可用或可能不可用的远程xml文件?
我还使用离子论坛的解决方案进行了测试,并在设备上安装构建后出现白屏.
我有以下反应代码:
render() {
const str = 'Line 1. **new-line** Line 2.';
return (
<p> {str} </p>
);
}
Run Code Online (Sandbox Code Playgroud)
我希望输出是:
Line 1.
Line 2.
Run Code Online (Sandbox Code Playgroud)
那就是 - 在单词之间添加一个新行。我试过了,\n但它不起作用。
这怎么可能实现?
编辑:字符串是从服务器接收的。
我有一个对象也保存在服务器中,我正在从该对象创建一个Backbone模型.
但是当我保存模型时,它正在执行PUT请求,这不是我想要的.如何告诉Backbone数据已经在服务器中而不进行提取?
我有一个骨干应用程序从服务器检索数据.这些数据是酒店和foreach酒店我有更多的房间.我已将酒店划分为json和另一个json内的房间,如下所示:
hotel.json
[
{
"id": "1",
"name": "Hotel1"
},
{
"id": "2",
"name": "Hotel2"
},
{
"id": "3",
"name": "Hotel3"
}
]
Run Code Online (Sandbox Code Playgroud)
rooms.json
[
{
"id" : "r1",
"hotel_id" : "1",
"name" : "Singola",
"level" : "1"
},
{
"id" : "r1_1",
"hotel_id" : "1",
"name" : "Doppia",
"level" : "2"
},
{
"id" : "r1_3",
"hotel_id" : "1",
"name" : "Doppia Uso singol",
"level" : "1"
},
{
"id" : "r2",
"hotel_id" : "2",
"name" : "Singola",
"level" : …Run Code Online (Sandbox Code Playgroud) 我使用火力地堡验证与VueJS,我需要一个转换的匿名auth用户的注册一个与谷歌.
我从一个例子中使用这段代码:
fromAnonymousToGoogle: function () {
// Authenticate with the first user then save the currentUser to a local variable
var previousUser = Firebase.auth().currentUser
// Authenticate with a second method and get a credential
var credential = Firebase.auth.GoogleAuthProvider()
previousUser.link(credential)
.catch(function (error) {
// Linking will often fail if the account has already been linked. Handle these cases manually.
alert(error)
})
// OAuth providers authenticate in an asynchronous manner, so you’ll want to perform the link account …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Jest 测试几个数据库实现。为了帮助测试这些实现,我首先针对两个实现都预期实现的 API 提出了一组单元测试。
我目前正在努力将这两个实现传递给测试套件。
以下是最简单形式的(虚拟)MongoDB 实现:
class MongoDB {
async query () {
console.warn(`This is a dummy function.`)
}
async connect () {
// The real connect takes some time..instead we just simulate it
await new Promise((resolve, reject) => {
setTimeout(resolve, 300)
})
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试的一小部分:
let db
beforeAll(async () => {
db = new MongoDB()
await db.connect()
console.log(`mongoDB ready`)
})
async function testDB (db) {
describe('Basic', async () => {
test('Valid instance', async () => {
expect(db).toBeTruthy() …Run Code Online (Sandbox Code Playgroud) const [count, setCount] = useState(0);
const handleClick = () =>
setCount(prevCount => {
return prevCount + 1;
});
Run Code Online (Sandbox Code Playgroud)
const [count, setCount] = useState(0);
const handleClick = () => setCount(count + 1);
Run Code Online (Sandbox Code Playgroud)
来自基于类的组件背景,它成为我们使用功能性的习惯setState。我想知道我们是否还需要在功能钩子中依赖 prevState ?或者当前状态始终是“可信赖的”和最“更新的”?
javascript ×9
backbone.js ×3
reactjs ×2
vue.js ×2
android ×1
apollo ×1
callback ×1
cordova ×1
css ×1
firebase ×1
graphql ×1
graphql-js ×1
html ×1
jestjs ×1
maven ×1
react-hooks ×1
react-native ×1
unit-testing ×1
vuejs2 ×1