gpt4 book ai didi

javascript - 使用 HTML LightSwitch 计算属性

转载 作者:行者123 更新时间:2023-11-28 01:48:04 24 4
gpt4 key购买 nike

我按照这里的教程:

Computed Properties With the LightSwitch HTML Client (lightswitchhelpwebsite.com)

这是教程代码:

myapp.AddEditFlowerShopOrder.NumberOfDetails_postRender = function (element, contentItem) {
function updateTotal() {
// Compute the total for the Order
contentItem.screen.TotalOfOrders =
TotalOrders(contentItem.screen.FlowerShopOrderDetail);
}
// Set a dataBind to update the value when the collection changes
contentItem.dataBind("screen.FlowerShopOrderDetail.count", updateTotal)
};
// Function to compute the total for the Order
function TotalOrders(OrderDetails) {
// Start with 0
var TotalAmountOfOrders = 0;
// Get the data for the collection passed
var OrderDetail = OrderDetails.data;
// Loop through each row
OrderDetail.forEach(function (order) {
// Add each row to TotalAmountOfOrders
TotalAmountOfOrders = TotalAmountOfOrders +
(order.Quantity * order.FlowerShopProduct.Price);
});
// Return TotalAmountOfOrders
return TotalAmountOfOrders;
}

这是我的代码:

myapp.AddEditOrder.Order_Subtotal_postRender = function (element, contentItem) {
//Write code here.
function subtotalDetails() {
contentItem.screen.Order.Subtotal =
TotalOrderDetails(contentItem.screen.OrderDetails);
}
subtotalDetails();

//contentItem.dataBind("screen.OrderDetails.count", subtotalDetails(contentItem));

};

function TotalOrderDetails(details) {
var subtotal = 0;
var detail = details.data;
detail.forEach(function (order) { subtotal = subtotal + order.Total; });
return subtotal;
}

我无法让 dataBind 绑定(bind),它说它无法返回调用。因此,我将其注释掉并仅调用一次,当它呈现以使其余代码正常工作时。我不知道 .data 成员是如何工作的,但如果我将 detail.forEach 更改为 for,它不会遍历 ProductDetails 的 ProductDetail 对象的集合。

澄清一下,我有这些表:Order >- OrderDetails。我的目标是绑定(bind) Order.Subtotal = Order.OrderDetail(all items).Total 的总和。

最佳答案

我在您的代码中看到的与演示的不同之处在于,演示使用屏幕属性来保存小计 (screen.TotalOfOrders),而您显然是在尝试更改订单记录 (screen.Order) 中的小计字段.小计)。请记住,要从子记录访问父表中的字段,您需要使用 screen.data.fieldnameyouwant 而不是 screen.ParentTable.fieldname。我知道第二种方式似乎是合乎逻辑的做法,但 Lightswitch 并不这么认为。

我想尝试的是像演示一样制作一个名为 DetailTotal 的屏幕属性,然后等到屏幕的验证事件触发并在那里更新父记录小计。这样,在您离开屏幕之前,实际上不会向父级写入任何内容。

myapp.AddEditOrder.beforeApplyChanges = function (screen) {
// Write code here.
var targetOrder = screen.findContentItem("Order_Subtotal");
targetOrder.data.Subtotal = screen.DetailTotal;
};

关于javascript - 使用 HTML LightSwitch 计算属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21395798/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com