收藏
回答

点击列表进入详情页时,其他的数据都显示在页面中,唯独有一个不显示在页面中?

当点击列表进入详情页时,其他都显示在页面中,唯独income没有显示出来,这是什么问题,怎么解决?

<!--pages/jobs/add/edit-position/edit-position.wxml-->
<view class="add-position-group">
   <expectation formjobs="{{formData.jobs}}" 
      formjobsCount="{{formData.jobsCount}}" 
      formindustries="{{formData.industries}}" 
      formindustriesCount="{{formData.industriesCount}}" 
      isEditMode="{{isEditMode}}" 
      expectationName="{{expectationName}}" 
      expectationCity="{{expectationCity}}" 
      income="{{income}}" 
      bindjobs="onJobs" 
      bindindustries="onIndustries" 
      bind:namechange="onNameChange" 
      bind:citychange="onCityChange" 
      bind:incomechange="onincomechange">
   </expectation>
   <view class="btn-ground">
      <button class="sunbmit-btn" style="width:200rpx;" bindtap="onDeleteConfig">删除</button>
      <button form-type="submit" type="primary" class="sunbmit-btn" bindtap="onSaveConfig">保存配置</button>
   </view>
</view>
// pages/jobs/add/edit-position/edit-position.js
const app = getApp();
const db = wx.cloud.database();
const _ = db.command;
Page({
   data: {
      formData: {
         jobs: [],
         jobsCount0,
         industries: [],
         industriesCount0
      },
      isEditModetrue,
      editItemId'',
      expectationName'全职'// 默认职位类型
      expectationCity'请选择工作城市'// 默认城市
      income'' // 初始为空
   },


   async onLoad(options) {
      try {
         await app.loadUserInfo();
         this.setData({
            editItemId: options.id,
         });
         if (options.id) {
            await this.loadEditData(options.id);
         }
      } catch (error) {
         console.error("app.loadUserInfo() 出错:", error);
      }
   },
 //加载编辑数据的方法
   async loadEditData(id) {
      try {
         const res = await db.collection('resume').where({
            _openid: app.globalData.openid,
         }).field({
            expectationtrue,
            _idfalse,
         }).get();
         console.log("res", res)
         console.log("res.data", res.data)
         console.log("res.data[0]", res.data[0])
         if (res.data && res.data.length > 0) {
            const expectationList = res.data[0].expectation || [];
            const target = expectationList.find(item => item.id === id);
            console.log("target", target)
            console.log("targetincome", target.income)
            if (target) {
               this.setData({
                  expectationName: target.expectationName || '全职',
                  expectationCity: target.expectationCity || '请选择工作城市',
                  income: target.income || '',
                  'formData.jobs': target.expectationPosition || [],
                  'formData.jobsCount': target.expectationPosition ? target.expectationPosition.length : 0,
                  'formData.industries': target.expectationIndustry || [],
                  'formData.industriesCount': target.expectationIndustry ? target.expectationIndustry.length : 0,
               });
            }
         }
      } catch (error) {
         console.error('加载编辑数据失败:', error);
         wx.showToast({
            title'加载数据失败',
            icon'none'
         });
      }
      console.log('after setData income:'this.data.income)  // 确认setData后income的值
   },
   /**
    * 薪资要求
    */
   onincomechange(e) {
      console.log(e)
      this.setData({
         income: e.detail.value
      });
   },
});
<!--components/expectation/expectation.wxml-->
<view class="expectation-container">
    <view class="add-list">
        <view class="add-list-title">薪资要求</view>
        <view class="list-content">
            <selector-tow name="income" pay-type="{{expectationName === '临/兼职' ? 'hourly' : 'monthly'}}" value="{{currentIncome}}" bindchange="onIncomeChange"></selector-tow>
        </view>
    </view>
</view>
// components/expectation/expectation.js
Component({
    properties: {
        income: {
            typeString,
            value'',
            observerfunction(newVal{
                console.log('income changed in component:', newVal)
                if (newVal) {
                    this.setData({
                        currentIncome: newVal
                    })
                }
            }
        }
    },
  
    data: {
        natures: [{id0,name'全职'}, {id1,name'临/兼职'}],
        selectedNature'',
        showPartTimeOnlyfalse,
        showFullTimeOnlyfalse,
        currentIncome'' 
    },
    lifetimes: {
        async attached() {
            console.log('attached - income:',this.properties.income )  // 这里应该能打印出值
            if (this.properties.income) {
                this.setData({
                    currentIncomethis.properties.income
                })
            }
        }
    },
    methods: {

    /**
     * 薪资要求
     */
    onIncomeChange(e) {
        console.log(e)
        const income = e.detail.value
        this.setData({
            currentIncome: income
        })
        this.triggerEvent('incomechange', { value: income })
      }
    }
});
<!--components/selector-tow/selector-tow.wxml-->
<view class="section">
   <picker mode="multiSelector" range="{{multiArray}}" value="{{multiIndex}}" bindchange="changeMulti" bindcolumnchange="nocolumnchange">
      <view class="section-picker">
         <view class="picker {{current === '请选择' ? 'address-red' : ''}}">
            {{current === '面议' ? '面议' : current}}
         </view>
         <icon class="icon"></icon>
      </view>
   </picker>
</view>
// components/selector-tow/selector-tow.js
const {
   hourlyWageList,
   monthlyPayList
} = require('../../utils/util')
Component({
   /**
    * 组件的属性列表
    */
   properties: {
      payType: {
         typeString,
         value'monthly' // hourly/monthly
      },
      income:{
         type:String,
         value:''
      }
   },
   /**
    * 组件的初始数据
    */
   data: {
      multiArray: [],
      classArray: [],
      multiIndex: [00],
      current'请选择',
   },
   observers: {
      'payType'(type) {
         const config = type === 'hourly' ? hourlyWageList : monthlyPayList
         this.setData({
            multiArray: config.multiArray,
            classArray: config.classArray,
            multiIndex: config.multiIndex,
            current: config.current
         })
      }
   },
   /**
    * 组件的方法列表
    */
   methods: {
      changeMulti(e) {
         const [col1, col2] = e.detail.value;
         const firstValue = this.data.multiArray[0][col1];
         const displayValue = firstValue === '面议' ? firstValue : `${firstValue}-${this.data.multiArray[1][col2]}`;
         this.setData({
            multiIndex: e.detail.value,
            current: displayValue
         });
         this.triggerEvent('change', {
            value: displayValue
         });
      },
      nocolumnchange(e) {
         const column = e.detail.column
         const value = e.detail.value
         const newData = {
            multiIndex: [...this.data.multiIndex],
            multiArray: [...this.data.multiArray]
         }
         if (column === 0) {
            newData.multiArray[1] = this.data.classArray[value]
            newData.multiIndex = [value, 0]
            this.setData(newData)
         }
      }
   }
})
回答关注问题邀请回答
收藏
登录 后发表内容