Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Mithril-重新加载动态内容_Javascript_Request_Deferred_Mithril.js - Fatal编程技术网

Javascript Mithril-重新加载动态内容

Javascript Mithril-重新加载动态内容,javascript,request,deferred,mithril.js,Javascript,Request,Deferred,Mithril.js,我试图在延迟对象返回数据后重新呈现DOM元素。我在控制台上调试它,看起来我的元素正在被创建,但是它从未显示在页面上。如果我添加静态内容,它将按预期工作 m('div', {class: 'table-responsive'}, [ m('table', {class: 'table'}, [ m("thead", [ m('tr', [

我试图在延迟对象返回数据后重新呈现DOM元素。我在控制台上调试它,看起来我的元素正在被创建,但是它从未显示在页面上。如果我添加静态内容,它将按预期工作

        m('div', {class: 'table-responsive'}, [
            m('table', {class: 'table'}, [
                m("thead", [
                    m('tr', [
                        m('th', '#'),
                        m('th', 'Groups'),
                    ])
                ]),
                m('tbody', findGroupsDeferred.promise.then(function(data){ // findGroupsDeferred returns when the promise is complete with my data.
                    data.group.map(function(group) {
                        return m("tr", [
                            m("td", [
                                m("input[type=checkbox] checked", {
                                    value: group,
                                    onclick: function (event) {
                                        if (event.target.checked) {
                                            ctrl.addGroup(ctrl.groups(event.target.value))
                                        } else {
                                            ctrl.removeGroup(ctrl.groups(event.target.value))
                                        }
                                    }
                                })
                            ]),
                            m("td", group),
                        ])
                    });
                }))
            ])
        ]),

我不认识米特里尔,但我猜诺言不能用那种方式

从承诺的第一原则来看,将整个
m()
表达式包装为
promise,然后(…)
,会更有意义。换句话说,在
findgroupsdeerred.promise
解析后构建整个表,而不是试图以表的内部部分为目标

findGroupsDeferred.promise.then(function(data) { // findGroupsDeferred returns when the promise is complete with my data.
    m('div', {class: 'table-responsive'}, [
        m('table', {class: 'table'}, [
            m("thead", [
                m('tr', [
                    m('th', '#'),
                    m('th', 'Groups'),
                ])
            ]),
            m('tbody', data.group.map(function(group) {
                return m("tr", [
                    m("td", [
                        m("input[type=checkbox] checked", {
                            value: group,
                            onclick: function (event) {
                                if (event.target.checked) {
                                    ctrl.addGroup(ctrl.groups(event.target.value));
                                } else {
                                    ctrl.removeGroup(ctrl.groups(event.target.value));
                                }
                            }
                        })
                    ]),
                    m("td", group),
                ]);
            }))
        ])
    ]),
});

或者,米特里尔有一个机制,这可能与此相关。

我不知道米特里尔,但我猜承诺不能以这种方式使用

从承诺的第一原则来看,将整个
m()
表达式包装为
promise,然后(…)
,会更有意义。换句话说,在
findgroupsdeerred.promise
解析后构建整个表,而不是试图以表的内部部分为目标

findGroupsDeferred.promise.then(function(data) { // findGroupsDeferred returns when the promise is complete with my data.
    m('div', {class: 'table-responsive'}, [
        m('table', {class: 'table'}, [
            m("thead", [
                m('tr', [
                    m('th', '#'),
                    m('th', 'Groups'),
                ])
            ]),
            m('tbody', data.group.map(function(group) {
                return m("tr", [
                    m("td", [
                        m("input[type=checkbox] checked", {
                            value: group,
                            onclick: function (event) {
                                if (event.target.checked) {
                                    ctrl.addGroup(ctrl.groups(event.target.value));
                                } else {
                                    ctrl.removeGroup(ctrl.groups(event.target.value));
                                }
                            }
                        })
                    ]),
                    m("td", group),
                ]);
            }))
        ])
    ]),
});

或者,米特里尔有一个机制,这可能与此相关。

我不知道米特里尔,但我猜承诺不能以这种方式使用

从承诺的第一原则来看,将整个
m()
表达式包装为
promise,然后(…)
,会更有意义。换句话说,在
findgroupsdeerred.promise
解析后构建整个表,而不是试图以表的内部部分为目标

findGroupsDeferred.promise.then(function(data) { // findGroupsDeferred returns when the promise is complete with my data.
    m('div', {class: 'table-responsive'}, [
        m('table', {class: 'table'}, [
            m("thead", [
                m('tr', [
                    m('th', '#'),
                    m('th', 'Groups'),
                ])
            ]),
            m('tbody', data.group.map(function(group) {
                return m("tr", [
                    m("td", [
                        m("input[type=checkbox] checked", {
                            value: group,
                            onclick: function (event) {
                                if (event.target.checked) {
                                    ctrl.addGroup(ctrl.groups(event.target.value));
                                } else {
                                    ctrl.removeGroup(ctrl.groups(event.target.value));
                                }
                            }
                        })
                    ]),
                    m("td", group),
                ]);
            }))
        ])
    ]),
});

或者,米特里尔有一个机制,这可能与此相关。

我不知道米特里尔,但我猜承诺不能以这种方式使用

从承诺的第一原则来看,将整个
m()
表达式包装为
promise,然后(…)
,会更有意义。换句话说,在
findgroupsdeerred.promise
解析后构建整个表,而不是试图以表的内部部分为目标

findGroupsDeferred.promise.then(function(data) { // findGroupsDeferred returns when the promise is complete with my data.
    m('div', {class: 'table-responsive'}, [
        m('table', {class: 'table'}, [
            m("thead", [
                m('tr', [
                    m('th', '#'),
                    m('th', 'Groups'),
                ])
            ]),
            m('tbody', data.group.map(function(group) {
                return m("tr", [
                    m("td", [
                        m("input[type=checkbox] checked", {
                            value: group,
                            onclick: function (event) {
                                if (event.target.checked) {
                                    ctrl.addGroup(ctrl.groups(event.target.value));
                                } else {
                                    ctrl.removeGroup(ctrl.groups(event.target.value));
                                }
                            }
                        })
                    ]),
                    m("td", group),
                ]);
            }))
        ])
    ]),
});

或者,米特里尔也有一个机制,可能与此相关。

罗默1888是非常正确的。这不能在视图中完成。您有几个选项可以实现这一点:

首先,在控制器中等待结果:

controller: function() {
  scope = {
    groups: []
  }
  findGroupsDeferred.promise.then(function(data) {
    scope.groups = data.group;
  }
  return scope;
},
view: function(scope) {
  return scope.groups.map(function(group) {
    return group.name // or what ever you want to do here
  }
}

另一个选项是为此创建一个函数,它几乎会导致相同的代码接受它所封装的。第三种选择是与推迟使用的米特里尔一起使用。

Roamer-1888是非常正确的。这不能在视图中完成。您有几个选项可以实现这一点:

首先,在控制器中等待结果:

controller: function() {
  scope = {
    groups: []
  }
  findGroupsDeferred.promise.then(function(data) {
    scope.groups = data.group;
  }
  return scope;
},
view: function(scope) {
  return scope.groups.map(function(group) {
    return group.name // or what ever you want to do here
  }
}

另一个选项是为此创建一个函数,它几乎会导致相同的代码接受它所封装的。第三种选择是与推迟使用的米特里尔一起使用。

Roamer-1888是非常正确的。这不能在视图中完成。您有几个选项可以实现这一点:

首先,在控制器中等待结果:

controller: function() {
  scope = {
    groups: []
  }
  findGroupsDeferred.promise.then(function(data) {
    scope.groups = data.group;
  }
  return scope;
},
view: function(scope) {
  return scope.groups.map(function(group) {
    return group.name // or what ever you want to do here
  }
}

另一个选项是为此创建一个函数,它几乎会导致相同的代码接受它所封装的。第三种选择是与推迟使用的米特里尔一起使用。

Roamer-1888是非常正确的。这不能在视图中完成。您有几个选项可以实现这一点:

首先,在控制器中等待结果:

controller: function() {
  scope = {
    groups: []
  }
  findGroupsDeferred.promise.then(function(data) {
    scope.groups = data.group;
  }
  return scope;
},
view: function(scope) {
  return scope.groups.map(function(group) {
    return group.name // or what ever you want to do here
  }
}
另一个选项是为此创建一个函数,它几乎会导致相同的代码接受它所封装的。第三种选择是与推迟使用的米特里尔一起使用