小编DI *_* MI的帖子

为矩阵的对角线条目赋值

我需要在for循环中访问并分配m*n矩阵的单个槽.到目前为止的代码:

rowCount <- 9
similMatrix = matrix(nrow = rowCount - 1, ncol = rowCount)
show(similMatrix)
for(i in (rowCount - 1)){
  for (j in rowCount)
    if (i == j){
      similMatrix[i == j] <- 0;
    }
}
show(similMatrix)
Run Code Online (Sandbox Code Playgroud)

因此,如果i = j,则矩阵中的NA值需要替换为0.

r matrix assign

11
推荐指数
2
解决办法
1万
查看次数

使用SAPUI5读取REST服务

我正在尝试使用SAPUI5访问REST服务.我在jQuery的帮助下发送了一个GET请求并期望JSON响应,但我得到的只是一个空的JSON对象.但是,使用RESTClient测试的REST服务给了我正确的响应.

这是我使用sofar的代码:

视图

sap.ui.jsview("sapui5_test.SAPUI5_Test", { 

    getControllerName : function() {
        return "sapui5_test.SAPUI5_Test";
    },

    createContent : function(oController) {

    var text = new sap.ui.commons.TextField( {  
        width : "100%"  
    }); 

// arrange controls on the page with a matrix layout  
    var ml = new sap.ui.commons.layout.MatrixLayout( {  
        columns : 2,  
        layoutFixed : true,  
        width : "500px"  
    }); 

    ml.addRow(new sap.ui.commons.layout.MatrixLayoutRow( {  
        cells : [  
            new sap.ui.commons.layout.MatrixLayoutCell( {  
                content : [ text ]  
            })]  
    }));

    var model = oController.initTodoModel();

    text.setValue(model.getJSON());
    return [ ml ];
    }   



});
Run Code Online (Sandbox Code Playgroud)

调节器 …

rest jquery json sapui5

6
推荐指数
1
解决办法
3万
查看次数

JavaScript对象失去了跨函数的引用

我正在使用一个小的待办事项列表应用程序测试SAPUI5框架.我有一个数据库并通过REST服务访问数据.我可以将所有内容放入我的UI,从UI进入数据库.

但是,我在JSON模型中保存数据库数据的引用,该模型映射到我在UI上显示的表.当我尝试添加/删除元素时,对数据库的写入似乎正常工作,但我的实习模型变量在不同的函数调用之间失去了引用(例如"initToDoModel"和"addToDo").这是代码:

  sap.ui.controller("sapui5_test.SAPUI5_Test", {

  //THIS IS THE REFFERENCE
  todoModel : null,            

        addTodo : function(text) {  
            this.doAjax("/add", {  
                text : text  
            }).done(function(todo) { 

                //HERE todoModel IS UNDEFINED BUT WAS SET IN initTodoModel
                this.todoModel.getProperty("/").push(todo); 
                this.todoModel.updateBindings();
                this.getView().rerender(); 
            });  
        },  

        initTodoModel : function() {    

            var oModel = new sap.ui.model.json.JSONModel();
            var aData = jQuery.ajax({
                type : "GET",
                contentType : "application/json",
                url : "http://sapm04.ibsolution.local:50000/demo.sap.com~d337_resttest_web/rest/todo/init/",
                dataType : "json",
                async: false,
                success : function(data,textStatus, jqXHR) {

                    oModel.setData({modelData : data});

                    //HERE THE todoModel IS SET
                    this.todoModel = oModel;
                    alert("Ok"); …
Run Code Online (Sandbox Code Playgroud)

javascript jquery sapui5

0
推荐指数
1
解决办法
1015
查看次数

标签 统计

jquery ×2

sapui5 ×2

assign ×1

javascript ×1

json ×1

matrix ×1

r ×1

rest ×1