Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Not able to assign JSON data from a service directly to the items variable. #171

Open
johnenosh92 opened this issue May 16, 2019 · 5 comments

Comments

@johnenosh92
Copy link

johnenosh92 commented May 16, 2019

I am not able to assign JSON data from a service directly to the items variable. It should accept any array of objects. If I do, the drop down shows all names as [object object]. In the Demo Application, there was a exported const array that was assigned. Would have to do the same to be able to display the data correctly?

@Crazyht
Copy link
Owner

Crazyht commented May 16, 2019

[object object] indicate you ask a complex object to be displayed. Check textField parameter correspond to a property of your object you want to display

@johnenosh92
Copy link
Author

[ { "data": { "branchID": 13, "branchName": "Hyderabad", "branchCode": "Hyd", "parentBranchId": null, "currentBranchId": null, "treeLevel": null } } ]

Above is the data I have and the tag attribute I have given is like this: textField="data.branchName".
I have multiple levels in the data. The number of levels are shown perfectly, but the text is shows as [object object]

@Crazyht
Copy link
Owner

Crazyht commented May 16, 2019

I'm not convinced path is well handled in text or id field property, never test this case. Finally, I call something like item[textField] to get value (item["data.branchName"] in your case), I think js don't handle this correctly.

@johnenosh92
Copy link
Author

The solution doesnt work.
My data is as below:
this.branches =[ { "data": { "branchID": 15, "branchName": "kachigoda", "branchCode": "kachi", "parentBranchId": null, "currentBranchId": null, "treeLevel": null }, "children": [ { "data": { "branchID": 18, "branchName": "uppal", "branchCode": "upl", "parentBranchId": null, "currentBranchId": null, "treeLevel": null }, "children": [ { "data": { "branchID": 19, "branchName": "chiluka Nagar", "branchCode": "upl", "parentBranchId": null, "currentBranchId": null, "treeLevel": null }, "children": [ { "data": { "branchID": 20, "branchName": "MalliKarjuna Nagar", "branchCode": "M N", "parentBranchId": null, "currentBranchId": null, "treeLevel": null }, "children": [] } ] } ] } ] } ]

And as suggested, I have given it like this in my template:
<tree-select name="Branch" [items]="branches" textField="branches['data.branchName']" childrenField="children"

Doesnt work.

@johnenosh92
Copy link
Author

The package is very confined and takes data if it is only in the format that you have provided. any change in nesting and naming convention {"id":03,name:"India"} seems to be compulsory after a lot of testing.

There seems to be other workaround other than rearranging the data to be in the same format as your demo has used.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants