{"id":2856,"date":"2024-11-10T16:24:33","date_gmt":"2024-11-10T08:24:33","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2856\/"},"modified":"2024-11-10T16:24:33","modified_gmt":"2024-11-10T08:24:33","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e4%b8%ad%ef%bc%8c%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e5%a4%9a%e4%b8%aa%e8%be%93%e5%85%a5%e6%a1%86%e7%9a%84%e5%80%bc%e7%9b%b8%e5%8a%a0%e5%b9%b6%e6%98%be","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2856\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\uff0c\u5982\u4f55\u5b9e\u73b0\u591a\u4e2a\u8f93\u5165\u6846\u7684\u503c\u76f8\u52a0\u5e76\u663e\u793a\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173089571246252.jpg\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\uff0c\u5982\u4f55\u5b9e\u73b0\u591a\u4e2a\u8f93\u5165\u6846\u7684\u503c\u76f8\u52a0\u5e76\u663e\u793a\uff1f\u63d2\u56fe\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\uff0c\u5982\u4f55\u5b9e\u73b0\u591a\u4e2a\u8f93\u5165\u6846\u7684\u503c\u76f8\u52a0\u5e76\u663e\u793a\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u8ba9\u5c0f\u7a0b\u5e8f\u4e2d\u7684\u591a\u4e2a\u8f93\u5165\u6846\u503c\u76f8\u52a0\u5e76\u663e\u793a<\/strong><\/p>\n<p>\u5728\u5c0f\u7a0b\u5e8f\u4e2d\uff0c\u5982\u6709\u591a\u4e2a\u8f93\u5165\u6846\u7528\u4e8e\u6536\u96c6\u7528\u6237\u8f93\u5165\uff0c\u9700\u8981\u4fdd\u7559\u5e76\u7d2f\u52a0\u8fd9\u4e9b\u8f93\u5165\u503c\uff0c\u5e76\u5728\u9875\u9762\u4e0a\u663e\u793a\u3002 voici les \u00e9tapes pour y parvenir&nbsp;:<\/p>\n<pre>Page({\n  data: {\n    values: [0, 0],  \/\/ \u8f93\u5165\u503c\u6570\u7ec4\uff0c\u521d\u59cb\u503c\u4e3a 0\n    sum: 0          \/\/ \u7d2f\u52a0\u7ed3\u679c\n  },\n  bindChange(e) {\n    const { value } = e.detail;\n    const index = parseInt(e.currentTarget.dataset.index);  \/\/ \u83b7\u53d6\u5f53\u524d\u8f93\u5165\u6846\u7684\u7d22\u5f15\n\n    this.data.values[index] = value;  \/\/ \u66f4\u65b0\u8f93\u5165\u503c\u6570\u7ec4\n\n    \/\/ \u8ba1\u7b97\u7d2f\u52a0\u7ed3\u679c\n    let sum = 0;\n    for (let num of this.data.values) {\n      sum += parseInt(num);\n    }\n\n    this.setData({\n      sum: sum\n    });\n  }\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5b9e\u73b0\u539f\u7406\uff1a<\/strong><\/p>\n<ol>\n<li>\u5728 data \u4e2d\u58f0\u660e\u4e00\u4e2a values \u6570\u7ec4\u6765\u5b58\u50a8\u8f93\u5165\u6846\u7684\u503c\u3002<\/li>\n<li>\u4f7f\u7528 bindchange \u4e8b\u4ef6\u76d1\u542c\u8f93\u5165\u6846\u7684\u8f93\u5165\u4e8b\u4ef6\u3002<\/li>\n<li>\u5728 bindchange \u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u4e2d\uff0c\u66f4\u65b0 values \u6570\u7ec4\u4e2d\u5f53\u524d\u8f93\u5165\u6846\u5bf9\u5e94\u7684\u503c\u3002<\/li>\n<li>\u904d\u5386 values \u6570\u7ec4\uff0c\u7d2f\u52a0\u6bcf\u4e2a\u8f93\u5165\u6846\u7684\u503c\u5e76\u5b58\u50a8\u5728 sum \u4e2d\u3002<\/li>\n<li>\u5c06 sum \u8bbe\u7f6e\u4e3a data \u4e2d\u7684 sum \u5c5e\u6027\uff0c\u4ece\u800c\u5728\u9875\u9762\u4e0a\u663e\u793a\u7d2f\u52a0\u7ed3\u679c\u3002<\/li>\n<\/ol>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5c0f\u7a0b\u5e8f\u4e2d\uff0c\u5982\u4f55\u5b9e\u73b0\u591a\u4e2a\u8f93\u5165\u6846\u7684\u503c\u76f8\u52a0\u5e76\u663e\u793a\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u8ba9\u5c0f\u7a0b\u5e8f\u4e2d\u7684\u591a\u4e2a\u8f93\u5165\u6846\u503c\u76f8\u52a0\u5e76\u663e\u793a \u5728\u5c0f\u7a0b\u5e8f\u4e2d\uff0c\u5982\u6709\u591a\u4e2a\u8f93\u5165\u6846\u7528\u4e8e\u6536\u96c6\u7528\u6237\u8f93\u5165\uff0c\u9700\u8981\u4fdd\u7559\u5e76\u7d2f\u52a0\u8fd9\u4e9b\u8f93\u5165\u503c\uff0c\u5e76\u5728\u9875\u9762\u4e0a\u663e\u793a\u3002 voici les \u00e9tapes pour y parvenir&nbsp;: Page({ data: { values: [0, 0], \/\/ \u8f93\u5165\u503c\u6570\u7ec4\uff0c\u521d\u59cb\u503c\u4e3a 0 sum: 0 \/\/ \u7d2f\u52a0\u7ed3\u679c }, bindChange(e) { const { value } = e.detail; const index = parseInt(e.currentTarget.dataset.index); \/\/ \u83b7\u53d6\u5f53\u524d\u8f93\u5165\u6846\u7684\u7d22\u5f15 this.data.values[index] = value; \/\/ \u66f4\u65b0\u8f93\u5165\u503c\u6570\u7ec4 \/\/ \u8ba1\u7b97\u7d2f\u52a0\u7ed3\u679c let sum = 0; for (let num of this.data.values) { sum += [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-2856","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2856","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=2856"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2856\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}