如何在sap.m.Datepicker中设置与上一行相同的行?
I have a table in which one of the Column has sap.m.Datepicker element. There is a checkbox which says "same start date for all" and a plus button to add a row. So when plus button is clicked i am pushing a empty row in the table model, but if check box is ticked then start date should be same in the new row as in previous row. But if i am unchecking the checkbox, still start date in a new row is setting the same. See the code below:
我有一个表,其中一个列有sap.m.Datepicker元素。有一个复选框,上面写着“所有开始日期相同”,还有一个加号按钮来添加一行。因此,当单击加号按钮时,我在表模型中推送一个空行,但如果勾选了复选框,则新行中的开始日期应与前一行相同。但是,如果我取消选中该复选框,仍然在新行中开始日期设置相同。请参阅以下代码:
var datepickered = new sap.m.DatePicker({
value: {
path:"{Start_Date}",
type: new sap.ui.model.type.Date({
pattern:"MMM dd yy",
source:{pattern:"MM/dd/yy"}
})
},});
Now i am setting the date in new row.
现在我将日期设置为新行。
var modelData = sap.ui.getCore().byId("tableid").getModel().getData();
var value = sap.ui.getCore().byId("tableid").getItems()[0].getCells()[3];
modelData.push({Start_Date:value.getValue()});
sap.ui.getCore().byId("tableid").setModel(modelData);
sanpshot of the rows
行的sanpshot
1 个解决方案
#1
0
Just call sap.ui.getCore().byId("tableid").getModel().refresh(true)
to refresh the model manually and apply the changes made on the underlying data object. It's unnecessary to use the sap.ui.getCore().byId("tableid").setModel(modelData)
code, because the model itself is already assigned to the table.
只需调用sap.ui.getCore()。byId(“tableid”)。getModel()。refresh(true)手动刷新模型并应用对基础数据对象所做的更改。没有必要使用sap.ui.getCore()。byId(“tableid”)。setModel(modelData)代码,因为模型本身已经分配给表。
Also make sure that sap.ui.getCore().byId("tableid").getModel().getData()
returns an array, not an object with a property which points to the desired array. It depends on your JSON data model.
还要确保sap.ui.getCore()。byId(“tableid”)。getModel()。getData()返回一个数组,而不是具有指向所需数组的属性的对象。这取决于您的JSON数据模型。
Edit: According to the attached JSBin source code, I found the following issues:
编辑:根据附带的JSBin源代码,我发现了以下问题:
var datepickerst = new sap.m.DatePicker({
value: {
path:"{Start_Date}",
type: new sap.ui.model.type.Date({
pattern:"MMM dd yy",
source:{pattern:"MM/dd/yy"}
})
}
});
You should align the pattern
and source
properties to support the same format (because you are using getValue()
, which will return the date in MMM dd yy
format, but the DatePicker
itself waits for a date in format MM/dd/yy
.
您应该对齐模式和源属性以支持相同的格式(因为您使用的是getValue(),它将以MMM格式返回日期,但DatePicker本身会以MM / dd / yy格式等待日期。
The other thing is that path
property should not contain the curly braces. Based on these things, a correct DatePicker
definition should look like this:
另一件事是path属性不应该包含花括号。基于这些东西,正确的DatePicker定义应该如下所示:
var datepickerst = new sap.m.DatePicker({
value: {
path:"Start_Date",
type: new sap.ui.model.type.Date({
pattern:"MMM dd yy",
source:{pattern:"MMM dd yy"}
})
}
});
Also make sure that you align pattern in the initialization phase of your code to the correct source format.
还要确保在代码的初始化阶段将模式与正确的源格式对齐。
更多相关文章
- 如何使用Require JS配置具有第三方js依赖项的日期选择器?
- 第三节(JavaScript 对象、日期,函数)
- 希望日期开始结束在一个数组中的while循环中为一个房间ID
- Javascript日期/时间函数是否依赖于客户端机器?
- 如何在我的页面上以漂亮的格式显示JSON对象?(复制)
- 获取指定日期的后(前)一(n)天(转)
- Python日期和时间函数
- Python 获得最近一个月的每天的日期
- 如何格式化Gtk.Entry中的条目