Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

vue.js - Vue js - not all the data showing after store dispatch

The select box not showing sometimes the first color and sometimes not showing the first color. How can i make it to show all the item in the select box? I'm not getting for some reason all the promises

You can see the issue in the picture Please help me to fix this issue i'm new to vue js

enter image description here

My code:

data() {
        return {
            propertiesTree: []
  }
}
getPropertyGroups(objectId: number): void {
            if (this.$data.currentObjectId === objectId)
                return;

            let component: any = this;

            this.$data.currentObjectId = objectId;

            component.showLoader();
            this.$store.dispatch('properties/getPropertyGroups', objectId)
                .then(({ data, status }: { data: string | Array<propertiesInterfaces.PropertyGroupDto>, status: number }) => {

                    // console.log(data, "data");
                    // console.log(status, "status")
                    if (status === 500) {
                        this.$message({
                            message: data as string,
                            type: "error"
                        });
                    }
                    else {
                        let anyData = data as any;
                        anyData.map(item => {
                            item.properties.map(prop => {
                                if(prop.type.toString() === 'dictionary'){
                                    prop.dictionaryList = [];
                                    prop.color = '';
                                    this.getWholeDictionaryList(prop.dictionaryId.value, prop)
                                }
                            });
                        });
              
                    }
                    component.hideLoader();
                });
        },
        getWholeDictionaryList(dictionaryId: number, prop: any){
            this.$store.dispatch('dictionaries/getWholeDictionaryList', dictionaryId).then(
                ({ data, status }: { data: Array<any> |string , status: number })  => {
                if (status === 500) {
                    this.$message({
                        message: data as string,
                        type: "error"
                    });
                } else {
                    const arrData = data as Array<any>;
                    arrData.map((item,index) => {
                        prop.dictionaryList = [];
                        prop.dictionaryList = data;                 
                        this.getDictionaryItemColor(item.id.value, data, index, prop);
                    });
                }
            });
        },
        getDictionaryItemColor(dictionaryItemId:number, dictionaryList: Array<any>, index:number, current){
            this.$store.dispatch('patterns/getDictionaryItemColor', dictionaryItemId).then((data: any, status: number) => {
                if (status === 500) {
                    this.$message({
                        message: data as string,
                        type: "error"
                    });
                } else{
                    debugger
                    if(current.dictionaryItemId.value === data.data.sceneObjectId)
                    current.color = data.data.colorString;
                     dictionaryList[index].color = data.data.colorString ? data.data.colorString: '#FFFFFF';

                }
            });
        },

Html code of the select box

  <el-select v-model="data.color" placeholder="Select">
    <el-option
      v-for="item in data.dictionaryList"
      :key="item.name"
      :label="item.color"
      :value="item.color">
    </el-option>
  </el-select>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I did return to dispatch

let dispatch = this.getWholeDictionaryList(prop.dictionaryId.value, prop)
let promiseArr = [];

promiseArr.push(dispatch); after the map closing tag i did

Promise.all(promisArr).then( () => {
                                        debugger
                                        this.$data.propertiesTree = anyData;
                                    });

And I've got it solved


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...