【发布时间】:2021-04-22 20:19:18
【问题描述】:
我正在使用带有一些自定义要求的 devExpress 表。
(更新) 休息了一天,然后返回并使用 React 样式正确地完成了它!感谢您的建议
在屏幕截图中,我禁用了某些单元格。但是,用户希望所有单元格看起来都被禁用,而不是选中的行。
使用这个
window
.$("td")
.not(document.getElementById(this.state.selection[0]))
.not(document.getElementsByClassName(this.state.selection[0]))
.not("td:first-child")
.not(window.$("td:contains('iPlay')"))
.not(window.$("td:contains('iLOE')"))
.not(window.$("td:contains('iInvest')"))
.not(window.$("td:contains('SPACER')"))
.not(window.$("td:contains('$MM')"))
.not(window.$("td:contains('$/BOE')"))
.attr("style", "color:#868a8f");
window
.$("td > div > div > div > input")
.not(document.getElementsByClassName(this.state.selection[0]))
.attr("style", "color:#868a8f");
我的问题是当我选择一个新行时,我无法删除之前未选择时应用的颜色。我正在尝试使用“has”来查找选定的行并将颜色更改回继承或完全删除样式属性。
window
.$("td")
.has(document.getElementById(this.state.selection[0]))
.has(document.getElementsByClassName(this.state.selection[0]))
.not("td:first-child")
.not(window.$("td:contains('iPlay')"))
.not(window.$("td:contains('iLOE')"))
.not(window.$("td:contains('iInvest')"))
.not(window.$("td:contains('SPACER')"))
.not(window.$("td:contains('$MM')"))
.not(window.$("td:contains('$/BOE')"))
.attr("style", "color:inherit");
window
.$("td > div > div > div > input")
.has(document.getElementsByClassName(this.state.selection[0]))
.attr("style", "color:inherit");
如果有帮助,我确实有未选择的行的 ID。 我试图用它做点什么,但没有任何运气
const otherRows = ExpensesUtils.ROW_PROPS.filter(x => x !== this.state.selection[0]);
for (let i = 0; i < otherRows.length; i += 1) {
window
.$("td")
.has(document.getElementById(otherRows[i]))
.has(document.getElementsByClassName(otherRows[i]))
.attr("style", "color:inherit");
window
.$("td > div > div > div > input")
.has(document.getElementById(otherRows[i]))
.has(document.getElementsByClassName(otherRows[i]))
.attr("style", "color:inherit");
}
链接到 HTML Table HTML
this.state.selection[0] 是从下面的列表中选择的 rowId
我已将 rowIds 应用于嵌套组件中的类。我想不出另一种访问它们的方法。
const ROW_PROPS = [
"leaseAndWellExpense",
"leaseAndWellExpenseBoe",
"iloeLeaseAndWellExpense",
"iloeLeaseAndWellExpenseBoe",
"gnaLeaseAndWell",
"gnaLeaseAndWellBoe",
"transportation",
"transportationBoe",
"divisionGnA",
"divisionGnABoe",
"gatheringProcessing",
"gatheringProcessingBoe",
"hqGnA",
"hqGnABoe",
"interestExpense",
"interestExpenseBoe",
"netProdBoe",
"leaseImpairments",
"leaseImpairmentsBoe",
"ddaProducing",
"ddaProducingBoe",
"iInvestDdaProducing",
"iInvestDdaProducingBoe",
"ddaGatheringProcessing",
"ddaGatheringProcessingBoe",
"iInvestDdaGatheringProcessing",
"iInvestDdaGatheringProcessingBoe",
"marketingCosts",
"otherIncomeExpense",
"otherIncomeExpenseBoe",
"otherRevenue",
"incomeTaxProvision",
"incomeTaxProvisionBoe",
"severanceTaxes",
"severanceTaxesPercent",
"currentTaxes",
"currentTaxesRate",
"netWellHeadRevenue",
];
【问题讨论】:
-
您能否添加(部分)HTML,以便我们知道如何处理。见Minimal, Reproducible Example
-
这是可怕的 JS。为什么要在 $ 上加上 window 前缀?为什么要混合使用 DOM 和 jQuery?我什至无法猜测
.has(document.getElementById(this.state.selection[0]))应该做什么? td 是否包含 ID = this.state.selection[0] 的元素???这与$('#'+this.state.selection[0])相同,然后我们可以过滤东西而不是使用不包含。如果我只知道this.state.selection[0]实际做了什么 -
@epascarello 是的,我不熟悉 jquery,我有一个截止日期!
-
你应该在 CSS 中创建一个样式表规则并添加一个类。删除一个类要容易得多。
-
我不会真正混合使用 ReactJS 和 jQuery。他们的编码方法非常非常不同。
标签: javascript html jquery css