Javascript Meteor angular ui路由器ui sref在一种情况下工作,而不是在另一种情况下工作
我正在使用mongoDB集合构建一个angular meteor应用程序,它的结构如下:Javascript Meteor angular ui路由器ui sref在一种情况下工作,而不是在另一种情况下工作,javascript,angularjs,meteor,angular-ui-router,Javascript,Angularjs,Meteor,Angular Ui Router,我正在使用mongoDB集合构建一个angular meteor应用程序,它的结构如下: { "_id" : "9YFoLcpDKFbJjHDoN", "name" : "Negative Thought 1", "betterThoughts" : [ { "name" : "bt", "_id"
{
"_id" : "9YFoLcpDKFbJjHDoN",
"name" : "Negative Thought 1",
"betterThoughts" : [
{
"name" : "bt",
"_id" : ObjectId("cdb4533e03a0a430b02320af")
}
]
}
该应用程序具有以下三种深度的结构
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");
});
以下是我的回购协议的链接,以防重要信息丢失:
为什么从级别1到级别2的链接有效,而从级别2到级别3的链接无效?尝试了一些方法,自己找到了解决方案。将ui sref更改为以下内容:
betterThoughtDetails({
betterThoughtId : betterThought._id._str
获取ObjectId对象的.\u str属性
<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>
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
}
}
}
);
};
}
};
});
betterThoughtDetails({
betterThoughtId : betterThought._id._str