Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

my.createSelectorQuery(...).select(...).fields is not a function

const \_my = require("../../\_\_antmove/api/index.js")(my);
// pages/gujia/gujia.js
import { request, ajax } from "../../utils/request.js";
Page({
data: {
// 定位
top: "0px",
bottom: "normal",
scrollTop: 0,
list: [],
canConfirm: false,
chooseValue: [],
last: [],
//原题目
id: "",
photo: "",
scrollTop: 0,
//默认滚动顶部距离
scrollIndex: 5,
//滚动索引
indexx: 0,
indexxAdd: 0,
shopgg: [],
//原题之前加几个题目
newaddCanzhao: [],
//匹配参照物(数组)
newAddList: [] //新增加题目的答案数组
// newAddValue: "", //新增加题目的答案-匹配答案值
},

async onLoad(options) {
const { id } = options;
const res = await request({
url: "justqusetion",
data: {
shopid: id
}
});
console.log("估价题目", options, res.data);
const list = res.data.data;
const photo = res.data.shop\_name;
let shopgg = res.data.shopgg;
let newaddCanzhao = res.data.sku;
this.setData({
list,
id,
photo,
shopgg,
newaddCanzhao
});
},

// 后增加的题目(仅单选)
fnaddQuestion(e) {
console.log("新增" + index, e.detail.value);
const { index } = e.currentTarget.dataset;
console.log(e.currentTarget.dataset, index);
this.data.newAddList[index] = e.detail.value; // this.data.shopgg[index].selected=!this.data.shopgg[index].selected
// if((index+1){console.log(res)
// }
// })
// return

\_my.createSelectorQuery()
.select(".contain\_box")
.fields(
{
dataset: true,
size: true,
scrollOffset: true,
properties: ["scrollX", "scrollY"],
computedStyle: ["margin", "backgroundColor"],
context: true
},
function(res) {
// console.log("测试",res)
\_my.createSelectorQuery()
.select(".contain")
.fields(
{
dataset: true,
size: true,
scrollOffset: true,
properties: ["scrollX", "scrollY"],
computedStyle: ["margin", "backgroundColor"],
context: true
},
function(res2) {
console.log("测试2", res, res2);

if (res2.height >= res.height) {
that.setData({
scrollTop: res2.height - res.height
});
that.setData({
top: "normal",
bottom: "10px"
});
}
}
)
.exec();
}
)
.exec();
},

// 重新展开题目
fndisplay(e) {
let { type, index } = e.currentTarget.dataset;
console.log(this.data.list, index);
console.log(this.data.list[index]);

if (type == 1) {
this.data.shopgg.forEach((v, ind) => {
v.selected = true;
});
this.data.list.forEach((v, ind) => {
if (ind != index) {
v.selected = true;
}
});
this.data.list[index].selected = !this.data.list[index].selected;
this.setData({
list: this.data.list,
shopgg: this.data.shopgg
});
} else {
this.data.list.forEach((v, ind) => {
v.selected = true;
});
this.data.shopgg.forEach((v, ind) => {
if (ind != index) {
v.selected = true;
}
});
this.data.shopgg[index].selected = !this.data.shopgg[index]
.selected;
this.setData({
shopgg: this.data.shopgg,
list: this.data.list
});
}
},

getElement(stor) {
console.log("节点器", \_my.createSelectorQuery().select(stor));

\_my.createSelectorQuery()
.select(stor)
.fields(
{
dataset: true,
mark: true,
rect: true,
size: true,
scrollOffset: true,
properties: ["scrollX", "scrollY"],
computedStyle: ["margin", "backgroundColor"],
context: true,
node: true
},
function(res) {
console.log("节点信息", res); // res.dataset // 节点的dataset
// res.width // 节点的宽度
// res.height // 节点的高度
// res.scrollLeft // 节点的水平滚动位置
// res.scrollTop // 节点的竖直滚动位置
// res.scrollX // 节点 scroll-x 属性的当前值
// res.scrollY // 节点 scroll-y 属性的当前值
// // 此处返回指定要返回的样式名
// res.margin
// res.backgroundColor
// res.context // 节点对应的 Context 对象
}
)
.exec();
},

async handleKan() {
const token = \_my.getStorageSync("token");

if (!token) {
\_my.showModal({
title: "提示",
content: "请先登录",

success(res) {
if (res.confirm) {
\_my.navigateTo({
url: "/pages/myLogin/myLogin"
});
} else if (res.cancel) {
console.log("用户点击取消");
}
}
});

return;
} // 处理增加题目

const { newAddList, newaddCanzhao } = this.data;
console.log("新增题目选中项", newAddList);
console.log("新增题目参照项", newaddCanzhao);
let newAddId = 0;
newaddCanzhao.forEach(v => {
v.sku.forEach(v2 => {
let uniIsTrue = true;
newAddList.forEach(answer => {
if (v2.indexOf(answer) < 0) {
uniIsTrue = false;
} else {
if (uniIsTrue) uniIsTrue = true;
}
});

if (uniIsTrue) {
newAddId = v.id;
console.log("选中项", v2, v);
}
});
});
console.log("选中id", newAddId); // // 处理原先题目

const { chooseValue, last, id, list } = this.data;

if (chooseValue.length != list.length - 1) {
\_my.showToast({
title: "还有选项未完成",
icon: "none"
});

return;
}

let arr = [...chooseValue, ...last];
console.log("提交参数", {
shopid: id,
just: arr,
id: newAddId
});
console.log("token", \_my.getStorageSync("token")); // return false

const res = await ajax({
url: "justmoney",
data: {
shopid: id,
just: arr,
id: newAddId
}
});
console.log("提交结果", res);
const price = Math.ceil(res.data.spgz);

if (res.data.status == 200) {
console.log(
"提交参数2",
"?price=" +
price +
"&name=" +
this.data.photo +
"&id=" +
this.data.id +
"&justid=" +
res.data.id
);

\_my.navigateTo({
url:
"/pages/yiban/yiban?price=" +
price +
"&name=" +
this.data.photo +
"&id=" +
this.data.id +
"&justid=" +
res.data.id
});
} else {
console.log("提交出错", res);
}
}
});

问题描述

问题出现的环境背景及自己尝试过哪些方法

相关代码

粘贴代码文本(请勿用截图)

你期待的结果是什么?实际看到的错误信息又是什么?


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

1 Answer

0 votes
by (71.8m points)

你要先找到是哪个对象没有找到,然后去排查问题。
my.createSelectorQuery(...).select(...).fields is not a function
my是否空值?
my.createSelectorQuery(...)是否空值?
my.createSelectorQuery(...).select(...)是否空值?

目测估计是select()的没有找到东西。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...