Javascript 在现有表中添加新行
我想在现有表中添加新行 我的代码:Javascript 在现有表中添加新行,javascript,model,sapui5,Javascript,Model,Sapui5,我想在现有表中添加新行 我的代码: onInit:function(){ var-oModel=new-sap.ui.model.json.JSONModel(“model/toughts.json”); this.getView().setModel(oModel); var table=this.getView().byId(“tableid”); 表.bindItems(“/catalog/clothing/categories”,新sap.m.ColumnListItem({ 键入:“导
onInit:function(){
var-oModel=new-sap.ui.model.json.JSONModel(“model/toughts.json”);
this.getView().setModel(oModel);
var table=this.getView().byId(“tableid”);
表.bindItems(“/catalog/clothing/categories”,新sap.m.ColumnListItem({
键入:“导航”,
按下:函数(evt){},
单元格:[
新sap.m.Text({
文本:“{name}”
}),新sap.m.Text({
正文:“{amount}”
}),新sap.m.Text({
案文:“{货币}”
}),新sap.m.Text({
文本:“{size}”
})
]
}));
表2.setModel(oModel);
},
onPress:功能(oEvent){
var table=this.getView().byId(“tableid”);
var items=table.getSelectedItems();
对于(变量i=0;i
这是我的输出图像
现在正是我想要实现的
Edit
按钮Edit
按钮我想在选中的复选框行下面再添加一行。
+1
作为新项的索引
是演示。如果使用数据绑定,则绝对不应添加新的表行控件,而是向模型节点添加新条目: 编辑:更新我的答案:
onPress : function(oEvent) {
var oModel = this.getView().getModel(); // the model
var aRows = oModel.getProperty("/catalog/clothing/categories"); // array with all rows in the model
var oThisObj = oEvent.getSource().getBindingContext().getObject(); // the current object
var item = { name: null, amount: null, currency: null, size: null } // an empty object
var index = $.map(aRows, function(obj, index) { // get the index of the selected item in your array
if(obj === oThisObj) {
return index;
}
})
aRows.splice(index, 0, item); // add the item at the index
oModel.setProperty("/catalog/clothing/categories", aRows); // store the array back to the model
}
谢谢@Dopedev,但如果我选择所有三行并按下编辑按钮,那么新行将添加到每个选定行的下方..现在它只添加到索引0..那么我该怎么做呢?我累了,但没有得到…@quality你能分享演示吗..ThanksIt只是简单的Javascript真的。。。。查看我的最新答案