我一直得到:
"VirtualizedList: missing keys for items, make sure to specify a key property on an item or provide a custom keyExtractor"
Run Code Online (Sandbox Code Playgroud)
非常混乱...,我传递的数组有一个在数组中的每个对象中定义的键属性.我在this.state中定义了该数组.我在控制台中快速打印出来以确定: 打印出阵列
数组中的每个对象定义为:
var obj = {key: doc.id, value: doc.data()};
Run Code Online (Sandbox Code Playgroud)
(doc和数据来自我的应用程序的另一部分,但我知道doc.id是唯一的)
经过一些谷歌搜索后,我尝试定义一个Key Extractor,如下所示:
_keyExtractor = (item, index) => item.key;
Run Code Online (Sandbox Code Playgroud)
然后这是我的平面列表定义:
<FlatList
style={{}}
data={this.state.FeedDataCollection}
keyExtractor={this._keyExtractor}
renderItem={(rowData) =>this.RenderFeedCard(rowData)}
/>
Run Code Online (Sandbox Code Playgroud)
仍然收到相同的错误,此时不确定如何处理这个或它做错了什么.有任何想法吗?非常感谢!
我目前的菜单中有一个项目,它是猪的图标。我想要发生的是当我点击猪时,图标会变成另一个像鸡一样的图像。我已经阅读了 StackOverFlow 上的其他论坛,但仍然没有运气。
我知道您不能使用 findViewbyId 来引用菜单项,但 findItem 方法对我不起作用,或者至少它说无效。请指教。
这是我当前的代码:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/menuImage"
android:title=""
android:icon="@drawable/pig"
android:orderInCategory="1"
app:showAsAction="always|withText"/>
</menu>
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.menuImage:
Toast.makeText(this, "YOU THINK YOU GOT THIS?", Toast.LENGTH_SHORT).show();
MenuItem changeImage = (MenuItem) findViewById(R.id.menuImage);
changeImage.setIcon(R.drawable.chicken);
return true;
}
return true;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将一些值从输入文本框推送到 JSON 数组。这是我尝试过的
代码:
<!DOCTYPE html>
<html>
<body>
<input id="studentnumber" placeholder="Student Number"></input>
<input id="status" placeholder="Status"></input>
<button id="bt1" onclick="newUser()">Validate</button>
<p id="demo"></p>
<script type="text/javascript">
//Array
var jsonStr =
'{"G11S":[{"StudentNumber":"1","status":"Pass"},{"StudentNumber":"2","status":"Pass"},{"StudentNumber":"3","status":"Pass"}]}';
function newUser(){
x = document.getElementById("studentnumber").value;
//Debug
console.log(x);
var obj = JSON.parse(jsonStr);
obj['G11S'].push({"StudentNumber": "4","status": "Member"}); // <~~ What am I Supposed to replace the "4" with and the "Member aswell"
jsonStr = JSON.stringify(obj);
console.log(jsonStr);
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
所以我试图通过定义一个变量 (x) 来将 'x' 推入数组中以获取输入文本框的值:
x = document.getElementById("studentnumber").value;
Run Code Online (Sandbox Code Playgroud)
尝试将其推送到第 25 行:
obj['G11S'].push({"StudentNumber": "4","status": "Member"});
Run Code Online (Sandbox Code Playgroud) 嗨,我正在开发一个phonegap应用程序.这是可滚动区域的代码
<div id = "contentoutter" style ="width:'+winwidth+'px;height:'+screendummy+';float:left;overflow-x:hidden;overflow-y:auto;margin-top:'+height50+'px;-webkit-overflow-scrolling: touch;position:relative;">
Run Code Online (Sandbox Code Playgroud)
这段代码是在javascript中,这个div被附加到body.有一个正确的垂直条,我无法摆脱.我怎么摆脱它?