我正在尝试使用React js和Angular迭代项目,并构建所需的模板,因为我正在以角度方式进行速度/组织问题。我遍历一系列项目,并为每个项目创建新的子范围,并使用该数据构建标记。我的问题是,有没有办法将新添加的子作用域附加到现有的控制器,以便连接控制器所具有的任何方法/变量?将角度绑定控制器添加到新范围
以下是可以访问父范围并创建子范围的React标记。例如,我想绑定一个示例控制器名称“CtrlItem”。这种事情可能吗?
var feedRepeat = React.createClass({
render: function() {
var template,
parent = this.props.scope,
child;
return (
<div>
{parent.items.list.map(function(item, i) {
if (!MVItems[item.type]) { return false; }
template = MVItems[item.type];
child = parent.$new(true)
child.data = item;
return (
<template scope={child} />
)
}, this)}
</div>
)
}
})
var MVItems = Object of templates...
更新
这里的角惹我试图解决。 基本上我通过ng-include加载了一个额外的模板,因为角度不会让我在指令实例化时加载动态模板。我觉得必须有一个更好的办法来编译比用模板NG-包括或NG开关
// main-view.html
<div class="results">
<article ng-repeat="item in items.list" class="item" ng-class="item.type">
<div ng-include="'views/items/' + item.type + '-template.html'" class="inner"></div>
</article>
</div>
// soundcloud-template.html
<soundcloud-music-item item="item"></soundcloud-music-item>
// the directive
myApp.directive 'soundcloudMusicItem', [ ->
restrict: 'E'
scope:
item: '='
controller: 'soundcloudMusic'
templateUrl: 'views/items/soundcloud-music-item.html'
link: (scope, el, attr, ctrl) ->
]
我试图做的是切断其干脆加载的SoundCloud,template.html。
我很想知道你用角度方法遇到的速度/组织问题。 –