how to use recyclerlistview in funtional component - react-native

I want use recyclerlistview in functional component in my app but i am not able to find proper example. any suggestions? My data set is
const data =
[
{
"key": "11",
"id": 1,
"name": "abc"
},
{
"key": "12",
"id": 2,
"name": "xyz"
},
]

Related

Grouping Response Data

I am trying to get data from my database but when I show and make it become api response, I have some problem for grouping it based on productid.
I have response data that created based on golang like this:
[
{
"product_id": "1",
"product_name": "Cardigan",
"pitems": [
{
"id": "625ad1bc-66c5-440e-a527-d029d401ec2b",
"name": "Box",
"qty": 1
},
{
"id": "625ad1bc-66c6-440e-a527-d029d401ec2b",
"name": "test items1",
"qty": 1
},
{
"id": "625ad1bc-66c7-440e-a527-d029d401ec2b",
"name": "test items2",
"qty": 1
},
{
"id": "625ad1bc-66c8-440e-a527-d029d401ec2b",
"name": "test items3",
"qty": 1
}
]
},
{
"product_id": "2",
"product_name": "Polo",
"product_sku": "P01",
"items": [
{
"id": "625ad1bc-66c5-440e-a527-d029d401ec2b",
"name": "Box",
"qty": 1
},
{
"id": "625ad1bc-66c6-440e-a527-d029d401ec2b",
"name": "test items1",
"qty": 1
},
{
"id": "625ad1bc-66c7-440e-a527-d029d401ec2b",
"name": "test items2",
"qty": 1
},
{
"id": "625ad1bc-66c8-440e-a527-d029d401ec2b",
"name": "test items3",
"qty": 1
}
]
}
]
But This response is not my expected result, my expected result is like:
[
{
"product_id": "1",
"product_name": "Cardigan",
"pitems": [
{
"id": "625ad1bc-66c5-440e-a527-d029d401ec2b",
"name": "Box",
"qty": 1
},
{
"id": "625ad1bc-66c6-440e-a527-d029d401ec2b",
"name": "test items1",
"qty": 1
},
{
"id": "625ad1bc-66c7-440e-a527-d029d401ec2b",
"name": "test items2",
"qty": 1
}
]
},
{
"product_id": "2",
"product_name": "Polo",
"product_sku": "P01",
"items": [
{
"id": "625ad1bc-66c8-440e-a527-d029d401ec2b",
"name": "test items3",
"qty": 1
}
]
}
]
Can Anyone help me to solve my problem?
What does it mean to show detailed data?
the easy way is:
create 2 func like this:
func detail(id int)(result model.Struct)
{ return result }
func product()(result model.Struct_Result) {
for data.Next() {
// call func detail
data.Scan(&id, &product)
detailResult := detail(id)
// then put together with struct and mix append ()
outputLoop := model.Result{
"product_id": id,
"pitems": [
{
"id": detailResult.id,
"name": detailResult.name,
"qty": detailResult.qty
},
]
}
result = append(result,outputLoop)
}
return result
}

how can I pass the props (id in particular) down to another component?

This is my first attempt at creating a react native project (with redux as well) and I have a question relating to passing down info. I have an API that looks like this :
[
{
"id": 1,
"name": "Module 1",
"topics": [
{
"id": 1,
"name": "Iterators and Helpers",
"course_id": 1
},
{
"id": 2,
"name": "Object Oriented Ruby",
"course_id": 1
},
{
"id": 3,
"name": "One to Many Relationships",
"course_id": 1
},
{
"id": 4,
"name": "Many to Many Relationships",
"course_id": 1
},
{
"id": 5,
"name": "Active Record Basics",
"course_id": 1
},
{
"id": 2,
"name": "Module 2",
"topics": [
{
"id": 9,
"name": "Introduction to Sinatra",
"course_id": 2
},
{
"id": 10,
"name": "Sinatra CRUD",
"course_id": 2
},
{
"id": 11,
"name": "Sinatra Associations",
"course_id": 2
},
{
"id": 12,
"name": "Introduction to Rails",
"course_id": 2
},
{
"id": 13,
"name": "Rails Forms + CRUD",
"course_id": 2
},
{
"id": 14,
"name": "Rails Associations + CRUD",
"course_id": 2
},
{
"id": 15,
"name": "Rails Sessions and Cookies",
"course_id": 2
},
{
"id": 16,
"name": "Rails Authentication and Authorization",
"course_id": 2
},
{
"id": 17,
"name": "Module 2 Project Guidelines",
"course_id": 2
}
]
{
"id": 3,
"name": "Module 3",
"topics": [
{
"id": 18,
"name": "Introduction to JavaScript",
"course_id": 3
},
{
"id": 19,
"name": "Introduction to Document Object Model",
"course_id": 3
},
{
"id": 20,
"name": "JavaScript Events",
"course_id": 3
},
{
"id": 21,
"name": "JavaScript Asynchronous Functionality + Fetch & CRUD",
"course_id": 3
Each 'module' has many topics. I want the Modules to appear on one screen and the topics for each course to appear once a button is clicked. I have this so far:
render(){
console.log(this.props.courseNames)
return(
<FlatList style={styles.flatlist} keyExtractor={(item)=> item.id} data={this.props.courseNames} ItemSeparatorComponent = { this.FlatListItemSeparator }
renderItem={({item}) => {
return <TouchableOpacity><Button title={item.name} onPress={() => this.props.navigation.navigate('Topics')} style={styles.listitem}/></TouchableOpacity>
}}
ListHeaderComponent = {this.header}/>
)
}
}
This is just a snippet but I'm wondering how I can pass down the information specific to that class so that I can retrieve all the topics that it contains and display them on the next screen. Any pointers would be great! thanks!
I think you're asking how to pass 'parameters' to navigation routes, which, yes, do render components that can receive props from the navigation route parameter.
In your case,
this.props.navigation.navigate('Topics')
should be changed to;
this.props.navigation.navigate('Topics', {id:item.id})
Once you navigate to your Topics route, that component will be able to read the 'id' value from;
props.route.params.id
Route parameters will be any object passed after the route name in this.props.navigation.navigate method.

Delete property from nested object using Lodash

Hi I have the following object:
{ "name": "Joe", "email": "joe.smith#test.com", "items": [ { "id": "1", "name": "Name 1" }, { "id": "2", "name": "Name 2" }...] }
I need to remove the name property from all the 'items', I have tried using omit but can't seem to get this working:
_.omit(this.user, ["items.name"]);
Any help would be great!
The _.omit() method doesn't work on multiple items in this way. You can use _.map() with _.omit():
const user = { "name": "Joe", "email": "joe.smith#test.com", "items": [ { "id": "1", "name": "Name 1" }, { "id": "2", "name": "Name 2" }] }
const result = {
...user,
items: _.map(user.items, user => _.omit(user, 'name'))
}
console.log(result)
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js"></script>

Extracting values from a JSON string

I want to retrieve the different tag values in an NSString.
NSString *test =
{
"data": [
{
"id": "100002319144563_125257217561582",
"from": {
"name": "Umair Ahmed",
"id": "100002319144563"
},
"message": "Hello Umair Here",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/100002319144563/posts/125257217561582"
},
{
"name": "Like",
"link": "http://www.facebook.com/100002319144563/posts/125257217561582"
}
],
"privacy": {
"description": "Everyone",
"value": "EVERYONE"
},
"type": "status",
"application": {
"name": "iPhone",
"id": "213257025359930"
},
"created_time": "2011-07-08T11:59:15+0000",
"updated_time": "2011-07-08T11:59:15+0000"
},
{
"id": "100002319144563_125251050895532",
"from": {
"name": "Umair Ahmed",
"id": "100002319144563"
},
"message": "Hello testing testing",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/100002319144563/posts/125251050895532"
},
{
"name": "Like",
"link": "http://www.facebook.com/100002319144563/posts/125251050895532"
}
]
}
]
}
How can I retrieve the name and message tag values into an array or dictionary?
It looks like a JSON string, so just use one of JSON libraries, like TouchJSON or JSONKit and you can easily extract the data from the structures they will provide you.

dojo how to get all tree node of specific type?

I wrote the following code to create a dojo tree.
store = new dojo.data.ItemFileWriteStore({url: link});
treeModel = new dijit.tree.TreeStoreModel({
store: store,
query: {
"type": "ROOT"
},
rootId: "newRoot",
childrenAttrs: ["children"]
});
tree= new dijit.Tree({model: treeModel},"treeOne");
Following is my JSON file structure :
{
identifier: "id",
label: "name",
items: [
{id: "ROOT",name: "Change Windows",type: "ROOT"},
]}
I want to get all the nodes (basically their 'id' part)of specific 'type',lets say type= "ROOT". Is there anyway to get all those node? I thought of doing this using tree._itemNodeMap, but don't know any way to iterate through this whole item map,because it need a id as a input to return any specific node.
If you're talking about obtaining the data items programatically, you can get them straight from the store using fetch.
Sample JSON for ItemFile*Store:
{
"identifier": "id",
"label": "name",
"items": [{
"id": "ROOT",
"name": "Root",
"type": "ROOT",
"children": [{
"id": "P1",
"name": "StackExchange",
"type": "website",
"children": [{
"id": "C1",
"name": "StackOverflow",
"type": "website"
},
{
"id": "C2",
"name": "ServerFault",
"type": "website"
}]
},
{
"id": "P2",
"name": "Sandwich",
"type": "food",
"children": [{
"id": "C3",
"name": "Ham",
"type": "food"
},
{
"id": "C4",
"name": "Cheese",
"type": "food"
}]
},
{
"id": "P3",
"name": "Potluck",
"type": "mixed",
"children": [{
"id": "C5",
"name": "Google",
"type": "website"
},
{
"id": "C6",
"name": "Banana",
"type": "food"
}]
}]
}]
}
Sample code:
dojo.require('dojo.data.ItemFileReadStore');
dojo.ready(function() {
var store = new dojo.data.ItemFileReadStore({
url: 'so-data.json'
});
store.fetch({
query: {
type: 'food'
},
queryOptions: {
deep: true
},
onItem: function(item) {
console.log(store.getLabel(item));
}
});
});
This will log Sandwich, Ham, Cheese, and Banana.