0
我建立一個角度流星應用程序與MongoDB的集合,這種結構:流星角UI路由器UI-SREF作品,而不是另一個
{
"_id" : "9YFoLcpDKFbJjHDoN",
"name" : "Negative Thought 1",
"betterThoughts" : [
{
"name" : "bt",
"_id" : ObjectId("cdb4533e03a0a430b02320af")
}
]
}
應用程序有三個結構如下深度
- 首頁:包含的消極想法
- 消極的想法列表:包含了更好的想法名單
- 更好認爲細節
點擊等級1中的負面思想會導致等級2中的負面思想。在2級點擊一個更好的想法但不會導致更好的思想的細節級別3
我的UI路由器的.config這個樣子的:
angular.module('better-thoughts').config(function ($urlRouterProvider, $stateProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$stateProvider
.state('thoughts', {
url: '/thoughts',
template: '<negs-list></negs-list>'
})
.state('betterThoughts', {
url: '/thoughts/:negId',
template: '<better-thoughts></better-thoughts>'
})
.state('betterThoughtDetails', {
url: '/thoughts/:negId/:betterThoughtId',
template: '<better-thought-details></better-thought-details>'
});
$urlRouterProvider.otherwise("/thoughts");
});
所以第2個狀態做工精細,第三一個沒有。
在思考(1級)消極的想法HTML我有這樣的代碼鏈接到下一個狀態(betterThoughts)的名單:
<li ui-sref="betterThoughts({ negId: neg._id })" ng-repeat="neg in negsList.negs">
{{neg.name}}
<button ng-click="negsList.removeNeg(neg)">X</button>
</li>
同樣,這個工程。
在更好的想法(2級)更好的想法,我有以下鏈接到下一個狀態(betterThought詳細信息)名單:
<ul>
<li ui-sref="betterThoughtDetails({ betterThoughtId: betterThoughts.neg.betterThought._id})"
ng-repeat="betterThought in betterThoughts.neg.betterThoughts">
{{betterThought.name}} </br>
{{betterThought._id._str}}
<button ng-click="betterThoughts.removeBetterThought(betterThought)">X</button>
</li>
</ul>
這是行不通的。
我只是將betterThoughts(2級)的指令包括在內以節省空間。
angular.module('better-thoughts').directive('betterThoughts', function() {
return {
restrict: 'E',
templateUrl: 'client/negs/better-thoughts/better-thoughts.html',
controllerAs: 'betterThoughts',
controller: function ($scope, $stateParams, $reactive) {
$reactive(this).attach($scope);
this.newBetterThought = {};
this.helpers({
neg:() => {
return Negs.findOne({ _id: $stateParams.negId });
}
});
this.save =() => {
Negs.update({_id: $stateParams.negId}, {
$set: {
name: this.neg.name,
}
}, (error) => {
if (error) {
console.log('Oops, unable to update the thought...');
}
else {
console.log('Done!', $stateParams);
}
});
};
this.addBetterThought =() => {
Negs.update(
{ _id : $stateParams.negId },
{
$push:
{ betterThoughts: {
name : this.newBetterThought.name,
_id : new Mongo.Collection.ObjectID()
}
}
}
);
this.newBetterThought = {};
};
this.removeBetterThought = (betterThought) => {
Negs.update(
{ _id : $stateParams.negId },
{
$pull: {
betterThoughts: {
_id: betterThought._id
}
}
}
);
};
}
};
});
這裏是重要的情況下的信息到我的回購鏈接丟失:https://bitbucket.org/mandyschippers/better-thoughts
爲什麼從1級到2級工作的聯繫,而不是從2級3級的聯繫?